API Clients PHP no work with PHP 7

I just installed the php client without Composer, and code errors “in the class” appear in the logs we are on php7,

Do you have an idea ?

Thank you,

Franck

Hey there,

Thanks for reaching out!
May I ask you for the full error you are getting? We are lacking a bit of info to troubleshoot this!

Thanks!

Hi, thanks for the return,
We just tested the ordering of the documentation,

require_once('../Lib/algoliasearch-client-php-master/algoliasearch.php');

$client = new \AlgoliaSearch\Client("MyAcount", "SecretKey");
$index  = $client->initIndex('contacts');
$batch  = json_decode(file_get_contents('./contacts.json'), true);
$index->addObjects($batch);

And here are the logs of error =

2017/06/02 17:12:36 [error] 18940#18940: *429766 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught AlgoliaSearch\AlgoliaException: Not enough rights to add an object near line:1 column:334 in /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php:992
Stack trace:
0 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php(809): AlgoliaSearch\Client->doRequest(Object(AlgoliaSearch\ClientContext), ‘POST’, ‘KeyAccount.algo…’, ‘/1/indexes/cont…’, Array, Array, 1, 30)
1 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Index.php(1259): AlgoliaSearch\Client->request(Object(AlgoliaSearch\ClientContext), ‘POST’, ‘/1/indexes/cont…’, Array, Array, Array, 1, 30)
2 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Index.php(169): AlgoliaSearch\Index->batch(Array)
3 /home/mysite/www/test/test3.php(28): AlgoliaSearch\Index->addObjects(Array)
4 {main}
_ thrown in /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php on line 992" while reading response header from upstream, client: 217.128.185.191, server: www.mysite.com, request: “GET /test/test3.php HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php7.0-fpm.sock:”, host: “www.mysite.com”_
2017/06/02 17:16:24 [error] 18935#18935: *430311 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught AlgoliaSearch\AlgoliaException: Not enough rights to add an object near line:1 column:334 in /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php:992
Stack trace:
0 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php(809): AlgoliaSearch\Client->doRequest(Object(AlgoliaSearch\ClientContext), ‘POST’, ‘KeyAccount.algo…’, ‘/1/indexes/cont…’, Array, Array, 1, 30)
1 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Index.php(1259): AlgoliaSearch\Client->request(Object(AlgoliaSearch\ClientContext), ‘POST’, ‘/1/indexes/cont…’, Array, Array, Array, 1, 30)
2 /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Index.php(169): AlgoliaSearch\Index->batch(Array)
3 /home/mysite/www/test/test3.php(28): AlgoliaSearch\Index->addObjects(Array)
4 {main}
_ thrown in /home/mysite/www/Lib/algoliasearch-client-php-master/src/AlgoliaSearch/Client.php on line 992" while reading response header from upstream, client: 217.128.185.191, server: www.mysite.com, request: “GET /test/test3.php HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php7.0-fpm.sock:”, host: “www.mysite.com”_

You also tested on php 5.5 and the problem is the same,
Thank you for your help,

Franck

It’s Ok, I am confused, The real problem came from the key Admin …
With php 7 I thought the worry came throw new AlgoliaException …

But that’s OK,

Thank you !

1 Like

Awesome, do not hesitate to reach out again!