How to setup a php client Thrift 0.9.1 ... - php

I'm trying to setup a php client for RPC with a HBase Thrift server but I'm getting some errors at the begining ... I've compilated the HBase.thrift file (with the 0.9.1 compiler) and I've put the 2 generated files like bellow (/ is the root of my project, I'm using apache server on ArchOS) :
/include/Hbase.php
/include/Types.php
I've included the lib folder of thrift0.9.1/lib/php/lib (composed of Thrift and sub folders) under / and so I've the following file system :
/include/HBase.php
/Types.php
/Thrift/Base
/ClassLoader
/Exception
/ext
...
To be able to use my service (HBase.php) I've to load files so my code is the following :
<?php
$GLOBALS['THRIFT_ROOT'] = PHYSICAL_PATH;
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
//hbase thrift
require_once ('Hbase.php');
require_once ('Types.php');
?>
When I'm charging the different files, I'm getting an error for this line --require_once ('Types.php');-- and the error is : Fatal error: Class 'Thrift\Exception\TException' not found in /var/www/html/POCThrift2/include/Types.php on line 1266
I understand it like : When I tried to include Types.php, the Thrift\Exception\TException namespace was not use (despite the use Thrift\Exception\TException; in the beginig of the Types file) but I don't know why I'm getting his error ... can you help me ? Does anyone has encountered this problem before ? Thx in advance, I'm stuuuck right now ...

Related

namespace class not found

I want to use this php library "Math-php-master" in my php script.
it is using namespaces.
My script is outside the library folder and the folder for the library is "MathPHP"
There is a php file "Finance.php" which I want to access.
path is "MathPHP/Finance.php". finance.php is using namespace MathPHP
and there is function irr() inside Finance.php which I need.
My code for accessing in my script is below:
include 'MathPHP/Finance.php';
use MathPHP\Finance;
$s = new MathPHP\Finance;
$val = $s->irr(array);
but when I run the script it is giving error "Uncaught Error: Class 'MathPHP\Finance' not found"
I tried everything, I tried the code given on github by the author but it is not working at all
link to the library on github: https://github.com/markrogoyski/math-php
Please help me.
thanks
You have not gone through the effort of readying the readme on how to use the library. In PHP most projects use composer and its autoloading to load classes.
Install composer if you do not have it https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
In short as the documentation suggests do
php composer.phar require markrogoyski/math-php:0.*
And in your code
require_once(__DIR__ . '/vendor/autoload.php');
use MathPHP\Finance;
// the rest of the code here

Fatal error: Uncaught Error: using graphaware for PHP

I am using graphaware to connect to a neo4j graph database. I keep getting an error saying Fatal error: Uncaught Error even though I'm using the library in composer.json. Here is the code for the autoload.php:
<?php
/*
* This file is part of the GraphAware Neo4j PHP OGM package.
*
* (c) GraphAware Ltd <info#graphaware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
error_reporting(E_ALL | E_STRICT);
$basedir = __DIR__.'/../';
//$basedir = __DIR__.'C:/xampp/htdocs/';
$proxyDir = $basedir.DIRECTORY_SEPARATOR.'_var';
putenv("basedir=$basedir");
putenv("proxydir=$proxyDir");
$loader = require_once __DIR__.'/../vendor/autoload.php';
Here us the code for the configuration php file named configNeo4j.php:
<?php
// Connection to the database
require_once __DIR__.'/vendor/autoload.php';
use GraphAware\Neo4j\Client\Client;
use GraphAware\Neo4j\Client\ClientBuilder;
$client = new Client ();
$client = ClientBuilder::create ()
->addConnection ( 'default', 'http://neo4j:neo4jj#127.0.0.1:7474' )
-> addConnection('bolt', 'bolt://neo4j:neo4jj#127.0.0.1:7687')
->build ();
$query = "MATCH (X) RETURN X";
$result = $client->run ( $query );
?>
Here is an image of the file structure:
Now when I run the webpage on a web browser which I am doing using xampps apache server I get this error message:
Fatal error: Uncaught Error: Class 'GraphAware\Neo4j\Client\Client' not found in C:\xampp\htdocs\configNeo4j.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\configNeo4j.php on line 11
This might also help:
This is strange because I am using the library in eclipse and I have also installed the composer in the php.exe file in xampp. If anyone has any solution to this problem it would be great if you could let me know how this problem can be fixed.Thanks in advance.
try this:
require_once __DIR__.'/vendor/autoload.php';
your code is:
require_once __DIR__.'C:/xampp/htdocs/vendor/autoload.php';
you dont need to specify the full path of the files ('c:/xampp/...')
__DIR__ will give you the current directory of the file you wrote your codes
oh and anyway, did you edit the autoload.php? if you use third party classes or plugins, you should not have to edit their core files.
Use better relative path to load autoload file. With this you are also making the app independent from the OS and your filesystem. Just like this:
require_once __DIR__.'/vendor/autoload.php';

laravel access native php script

I'm trying to run a native php script using laravel routes.php , view, controller. but no chance.
for example if i have a test.php inside views path and require it in a view blade:
<?php
require_once 'test.php';
?>
then build a route to that view and point to it:
FatalErrorException in b012cb264e405ddcdbcd54b1275905692fac6df9.php line 26:
main(): Failed opening required 'test.php' (include_path='.;E:\xampp\php\PEAR')
Try something like
require_once base_path('resources/views').'/test.php';
Or
This is in your config/view.php
require_once Config::get('view.paths').'/test.php';
Laravel 5+ (Global config)
require_once config('view.paths').'/test.php';

Require paths not working using google api php library

My problem is the next one,
I tried to integrate the google login using OAuth 2.0 feature into my company backend.
I tested it on my domain , www.gabrielestevez.com, everything here works perfect, there is no problem with the require paths, everything runs smothly
But , the company backend directories has the following structure
I'm using a mvc framework developed by me , the Google_SL.php file contains the class where I make the first two require_once
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';
which works fine, but then when it goes to the client.php and is trying to load this class
require_once 'Google/Auth/AssertionCredentials.php';
is not working , this is the error
An error occurred in script '/home/xxx/public_html/admin/hmf/Core/library/auth/Google/Client.php' on line 18: require_once(Google/Auth/AssertionCredentials.php) [function.require-once]: failed to open stream: No such file or directory
Date/Time: 9-19-2014 11:50:29
, I don't want to change manually all the path within this library because I know there is got to be a better solution to this
any input is appreciated.
for future reference
I fixed my issue using this
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/admin/hmf/Core/library/auth/' . PATH_SEPARATOR . get_include_path());
Try use __DIR__ to get the current directory of the script. Not exactly sure where your AssertionCredentials.php is, but try something like
require_once(__DIR__ . '/Google/Auth/AssertionCredentials.php');

Using Unirest php lib that has a namespace

I'm trying to use unirest, a new php lib for making rest calls.
I'd like to place it in a system-wide directory above my project. I then include it:
require_once ('../unirest-php-master/lib/Unirest/Unirest.php');
loads fine. Then I use it per the readme:
$response = Unirest::post(CSWA_URL ....
I get Fatal error: Class 'Unirest' not found in ...hello_world/sign_start.php on line 23
I then try to use the namespace (see the library's code. They use a Namespace Unirest statement before declaring the Unirest class.)
$response = Unirest\Unirest::post(CSWA_URL ....
I got further. Now: Fatal error: Class 'Unirest\HttpMethod' not found in ....unirest-php-master/lib/Unirest/Unirest.php on line 26 -- This is an error in the library code!
Q: Did I do something wrong? Did the authors of Unirest make a mistake? Do I have to place the library in ./lib? What's the best fix?
It looks like the Unirest code in Unirest.php relies on autoloading code from the two other files in the unirest lib directory (HttpMethod.php and HttpResponse.php).
The author suggests installing the package using composer, if you were to do that composer would add the Unirest namespace to the autoloader.php script it generates. From there you need to require the autoload.php file at the top of your script and it will handle loading classes that aren't defined.
Alternatively, if you don't want to use composer, I would just require the other two files in the unirest lib directory at the top of your script as well.

Categories