Error handlers in neo4j-php-client - php

I downloaded and installed neo4j-php-client and neo4j 2.3.2. Actually all works fine, but I just wondering why there is no error handlers in this php client? For example if there is an error in cypher query, no error has throwing to be easy to catch it. I searching through the network, but I can't found a solution.
Do anybody have an idea how to turn on error handlers?
Thanks in advance.

I'm the maintainer of neo4j-php-client.
When you send a query to Neo4j, it is actually sent via Guzzle.
Of course there is a try/catch block for handling exceptions, which is located here :
https://github.com/graphaware/neo4j-php-client/blob/master/src/HttpClient/GuzzleHttpClient.php#L76
If there is an error in your cypher query, an exception will be thrown of course, the exception is of type Neo4jException (https://github.com/graphaware/neo4j-php-client/blob/master/src/Exception/Neo4jException.php)
Here is a simple code with a cypher syntax error and you can see an exception is thrown :
<?php
require_once __DIR__ .'/vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default', 'http', 'localhost', 7474)
->setAutoFormatResponse(true)
->build();
$query = 'MATCH (n) RETURN x';
$result = $client->sendCypherQuery($query)->getResult();
-
ikwattro#graphaware ~/d/g/p/neo4j-php-client> php test.php
PHP Fatal error: Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117
Fatal error: Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117

Thanks for the answer. The problem is seems on my end, I figured out after few tests - Error hanldering overwrites by the php framework.

Related

Authentication issues

I have been using the API with no problems for a long time. All of a sudden I'm getting this error:
PHP Fatal error: Uncaught PodioError
Request URL:
Stack Trace:
#0 /srv/users/serverpilot/apps/dellentconsulting/public/vendor/podio/lib/Podio.php(93): Podio::request('POST', '/oauth/token', Array, Array)
#1 /srv/users/serverpilot/apps/dellentconsulting/public/pages/careers.php(97): Podio::authenticate('app', Array)
#2 /srv/users/serverpilot/apps/dellentconsulting/public/index.php(58): include('/srv/users/serv...')
#3 {main}
thrown in /srv/users/serverpilot/apps/dellentconsulting/public/vendor/podio/lib/Podio.php on line 283
I didn't make any changes in my code, or applications key.
The error occurs in this code fragment:
<?php
require_once 'vendor/podio/PodioAPI.php';
require_once 'vendor/podio/utils/config-careers.php';
Podio::setup(CLIENT_ID, CLIENT_SECRET);
if (!Podio::is_authenticated()) {
Podio::authenticate('app', array('app_id' => APP_ID, 'app_token' => APP_TOKEN));
}
I already made a restart to the server.
Bit of a wild guess, but could it be a network issue, did you check that you can reach Podio API from the server all the time?

Laravel 5.1 illuminate/queue capsule error 'Class encrypter does not exist'

I have the need to push jobs on a queue from outside the Laravel framework. Found the queue capsule manager that should make this possible:
https://github.com/illuminate/queue
Trying the following as per their example code:
<?php
require_once __DIR__ . '/../../bootstrap/autoload.php';
use Illuminate\Queue\Capsule\Manager as Queue;
$queue = new Queue;
$queue->addConnection([
'driver' => 'sync',
]);
$queue->setAsGlobal();
$queue->push(function($job)
{
echo "test!\n";
$job->delete();
});
Running this code results in the following error:
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class encrypter does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('encrypter')
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('encrypter', Array)
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(1163): Illuminate\Container\Container->make('encrypter')
#3 vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(117): Illuminate\Container\Container->offsetGet('encrypter')
#4 vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php(135): Illuminate\Queue\QueueM in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741
Fatal error: Uncaught exception 'ReflectionException' with message 'Class encrypter does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('encrypter')
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('encrypter', Array)
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(1163): Illuminate\Container\Container->make('encrypter')
#3 vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(117): Illuminate\Container\Container->offsetGet('encrypter')
#4 vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php(135): Illuminate\Queue\QueueM in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741
Searching on this subject I found something that said to add the following code:
$queue->getContainer()->bind('encrypter', function() {
return new Illuminate\Encryption\Encrypter('nInrMfTMQngxqRvoFpjstYjZX0qH1Nlr', 'AES-256-CBC');
});
$queue->getContainer()->bind('request', function() {
return new Illuminate\Http\Request();
});
Which does not seem to be a solution, because I then get the following error:
PHP Fatal error: Uncaught exception 'Illuminate\Contracts\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Encryption\Encrypter] is not instantiable.' in vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 vendor/laravel/framework/src/Illuminate/Container/Container.php(842): Illuminate\Container\Container->make('Illuminate\\Cont...')
#2 vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#3 vendor/laravel/framework/src/Illuminate/Container/Container.php(776): Illuminate\Container\Container->getDependencies(Array, Array)
#4 in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 749
Binding those should not be needed though, judging by the documentation from illuminate/queue.
This occurs with laravel 5.1.27. Any thoughts/solutions?
Update: I have tried it in a 4.2 environment, there I also have to bind the encrypter class, but doing that there works. (Does not give the not instantiable error)
After playing around a bit you should add one more binding, after the encrypter binding, to get around this issue.
$queue->getContainer()->bind('Illuminate\Contracts\Encryption\Encrypter', 'encrypter');
Binding the encrypter to the contract.

How to make zf2 output errors with simple formatting?

I am newbie with zf2 framework. For example, now I get this error:
Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZfcUserOverride) could not be initialized.' in F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php:189 Stack trace:
#0 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(163): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZfcUserOverride')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('loadModules', Object(Zend\ModuleManager\ModuleEvent), NULL)
#5 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(109): Zend\EventManager\EventManager->trigger('loadModules', Object(Zend\ModuleManager\ModuleManager), Object(Zend\ModuleManager\ModuleEvent))
#6 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(252): Zend\ModuleManager\ModuleManager->loadModules()
#7 F:\Server\domains\zf2-skeleton\public\index.php(17): Zend\Mvc\Application::init(Array)
#8 {main} thrown in F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php on line 189
I formatted it manually, so you can read correct error.
It is hard to do it all time I get some error. How I can make zf2 to output such errors correctly?
I need something like this:
The ZendSkeletonApplication comes with a template that reports errors in a readable format. If you install the ZendSkeletonApplication and build your application off of it, you’ll benefit from this template and other conveniences. Alternatively, you can use just the standard error template or create your own.

Zf2 "The iterator class does not exist" on Session\Container definition

Sometimes on my website (ZendFramework2), I get an error when setting a session variable.
The error:
PHP Fatal error: Uncaught exception 'Zend\\Stdlib\\Exception\\InvalidArgumentException' with message 'The iterator class does not exist' in /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php:374
Stack trace:
#0 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php(414): Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->setIteratorClass(NULL)
#1 [internal function]: Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->unserialize('a:4:{s:7:"stora...')
#2 /MySite/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start()
#3 /MySite/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\\Session\\SessionManager->start()
#4 /MySite/module/Application/Module.php(97): Zend\\Session\\AbstractContainer->__construct('site')
#5 [internal function]: Application\\Module->onBootstrap(Object(Zend\\Mvc\\MvcEvent))
#6 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php on line 374
Code Module.php line 97 :
$s_site = new \Zend\Session\Container('site');
I try but I can not find why. Do you have any idea? Need more informations?
Thank you.
The is a result of the setIteratorClass method in ArrayObject/PhpReferenceCompatibility being passed a null $class argument. I'm not sure why it sometimes gets a null, but the way I fixed it in my case was to set the iterator class as 'ArrayIterator' when passed a null object, like this:
if (!isset($class)) {
$class = 'ArrayIterator';
}
In the latest zf2 version, the ArrayObject/PhpReferenceCompatibility class has been removed, so please make the change in stdlib/ArrayObject.php.

XMLRPC calling SOAP need to return response instead of crashing/dying

So I have a XMLRPC developed in Zend PHP which calls a SOAP request to start another process (SOAP is not my script but the XMLRPC is).
During the SOAP request if the host is not found, this sometimes crashes my XMLRPC call.
How can I return the XMLRPC request with a response instead of an error? Does the logic look ok? I know all the functionality works and I have gotten the response I desire (sometimes) but I need to make sure the script doesn't crash. Any thoughts? tips?
Here is what I have
try {
$soap_call = new ReportSoapClient();
$soap_call->RunReport();
} catch(Exception $e) {
// Set the Error Alert Email Message
$this->setErrorAlertMessage($this->getErrorAlertMessage()."ERROR: SOAP Exception: ".$e->getMessage());
// Send the Email
$this->sendErrorAlertEmail();
// This set the XMLRPC Response
$this->setXMLRPCResponse('Code: '.$e->getCode().' Message: '.$e->getMessage());
// This is a logger
$this->debug('Code: '.$e->getCode().' Message: '.$e->getMessage());
// Return the XMLRPC Response
return $this->getXMLRPCResponse();
}
Here is the email I get:
ERROR: SOAP Exception: Could not connect to host
Here is the error I get when crashing (happens only sometimes, why???):
Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 10 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(70): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7 {main}
thrown in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512
I increased the timeout to 30 seconds (<-- Link: if you need to see how) and then I sometimes get this: (again why???):
Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 30 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(23): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7 in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512
Here is what comes back sometimes (this is the desired response):
Code: 0 Message: Could not connect to host
it was the SOAP process erroring out and wasn't throwing the error properly. ugh

Categories