PHP PhantomJS not loading in class via Composer

I have completed the installation guide for PHP PhantomJS . When running a test script using PHP PhantomJS, I get an error message:

PHP Fatal error: Class 'JonnyW\PhantomJs\Client' not found in ...

I have not used Composer before, so I may have missed something. I run this from MAMP, so there may be some features related to those that are not mentioned in the documentation. If I open the test script in the browser, I get a blank screen. It is only from running php from Terminal that I get Fatal error .

The script line does not work:

 $client = Client::getInstance(); 

Therefore, I assume that it does not load correctly from Composer. I can verify that both phantomjs and phantomloader are in /bin .

What steps should be taken to properly load the PHP PhantomJS script?

- update -

test.php (taken directly from PHP PhantomJS example)

 use JonnyW\PhantomJs\Client; $client = Client::getInstance(); $request = $client->getMessageFactory()->createRequest(); $response = $client->getMessageFactory()->createResponse(); $request->setMethod('GET'); $request->setUrl('http://google.com'); $client->send($request, $response); if($response->getStatus() === 200) { echo $response->getContent(); } 
+6
source share
1 answer

You will have to include the composer autoloader in your script if you are not using it yourself.

 require 'vendor/autoload.php'; 

This is an autogenerated autoload script composer. See here https://getcomposer.org/doc/01-basic-usage.md#autoloading

I am afraid that the Use statement will not care about startup, it will simply define a namespace for searching the Client class.

+10
source

Source: https://habr.com/ru/post/983530/


All Articles