params.json 8.3 KB

1
  1. {"name":"php-phantomjs","tagline":"Execute PhantomJS commands through PHP","body":"PHP PhantomJS\r\n=============\r\n\r\nPHP PhantomJS is a simple PHP library to load pages through the PhantomJS \r\nheadless browser and return the page response. It is handy for testing\r\nwebsites that demand javascript support and also supports screen captures.\r\n\r\n[![Total Downloads](https://poser.pugx.org/jonnyw/php-phantomjs/downloads.png)](https://packagist.org/packages/jonnyw/php-phantomjs) [![Latest Stable Version](https://poser.pugx.org/jonnyw/php-phantomjs/v/stable.png)](https://packagist.org/packages/jonnyw/php-phantomjs) [![Build Status](https://travis-ci.org/jonnnnyw/php-phantomjs.png?branch=master)](https://travis-ci.org/jonnnnyw/php-phantomjs) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/jonnnnyw/php-phantomjs/badges/quality-score.png?s=631d32fa1fbb9300eb84b9b52702c7ffeac046a1)](https://scrutinizer-ci.com/g/jonnnnyw/php-phantomjs/) [![Code Coverage](https://scrutinizer-ci.com/g/jonnnnyw/php-phantomjs/badges/coverage.png?s=893b5997da45448e32983b8568a39630b0b2d91b)](https://scrutinizer-ci.com/g/jonnnnyw/php-phantomjs/)\r\n\r\n0.0 Table of Contents\r\n---------------------\r\n\r\n* Introduction\r\n* Examples\r\n* Changelog\r\n* Troubleshooting\r\n\r\n\r\n1.0 Introduction\r\n----------------\r\n\r\nThis library provides the ability to load pages through the PhantomJS \r\nheadless browser and return the page response. It also lets you screen\r\ncapture pages and save the captures to disk. It is designed to meet a \r\nsimple objective and does not offer a PHP API to the full suite of \r\nPhantomJS functionality.\r\n\r\nThe PhantomJS executable comes bundled with the library. If installed\r\nvia composer, the file will be symlinked in your bin folder.\r\n\r\nIf you are looking for a PHP library to run external javascript files \r\nthrough PhantomJS then this is not for you. Check out [PhantomJS runner](https://github.com/Dachande663/PHP-PhantomJS).\r\n\r\n\r\n2.0 Examples\r\n------------\r\n\r\nRequest a URL and output the reponse:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request\r\n$client->send($request, $response);\r\n\r\nif($response->getStatus() === 200) {\r\n\t\r\n\t// Dump the requested page content\r\n\techo $response->getContent();\r\n}\r\n```\r\n\r\n\r\nRequest a URL with delay and output the reponse:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request with delay in miliseconds\r\n$client->open($request, $response, $delay = 5000);\r\n\r\nif($response->getStatus() === 200) {\r\n\t\r\n\t// Dump the requested page content\r\n\techo $response->getContent();\r\n}\r\n```\r\n\r\n\r\nRequest a URL, save a screen capture to provided location and return the response:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request\r\n$client->send($request, $response, '/path/to/save/screen/capture.png');\r\n```\r\n\r\nSend post request with data:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest();\r\n\r\n$request->setMethod('POST');\r\n$request->setUrl('http://google.com');\r\n\r\n$request->setRequestData(array(\r\n\t'name' \t=> 'Test',\r\n\t'email' => 'test@jonnyw.me'\r\n));\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request\r\n$client->send($request, $response);\r\n```\r\n\r\nSet a request header:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest();\r\n\r\n$request->addHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2 Safari/534.34');\r\n```\r\n\r\nGet a response header:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request\r\n$client->send($request, $response, '/path/to/save/screen/capture.png');\r\n\r\necho $response->getHeader('Cache-Control');\r\n```\r\n\r\nHandle response redirect:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Request \r\n **/\r\n$request = $client->getMessageFactory()->createRequest('GET', 'http://google.com');\r\n\r\n/** \r\n * @see JonnyW\\PhantomJs\\Message\\Response \r\n **/\r\n$response = $client->getMessageFactory()->createResponse();\r\n\r\n// Send the request\r\n$client->send($request, $response);\r\n\r\nif($response->isRedirect()) {\r\n\techo $response->getRedirectUrl();\r\n}\r\n\r\n```\r\n\r\nDefine a new path to the PhantomJS executable:\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n$client->setPhantomJs('/path/to/phantomjs');\r\n```\r\n\r\nSet timeout for the request (defaults to 5 seconds):\r\n\r\n```php\r\n<?php\r\n\r\nuse JonnyW\\PhantomJs\\Client;\r\n\r\n$client = Client::getInstance();\r\n$client->setTimeout(10000); // In milleseconds\r\n```\r\n\r\n3.0 Changelog\r\n------------\r\n\r\n### V2.0.0\r\n\r\nVersion 2.0.0 changes the way requests are made. Requests now require you \r\nto inject a request and response instance into the send method. The examples \r\nabove illustrate how to make requests in version 2.0.0 and will not work \r\nfor older versions.\r\n\r\n* Requests now require you to inject a request and response instance when sending.\r\n* Added message factory that can also be injected into client when instantiated.\r\n* Custom headers can be set in requests.\r\n* Request method can be set. Supports: OPTIONS, GET, HEAD, POST, PUT, DELETE, PATCH.\r\n* Request data can be set. Useful when making post requests.\r\n\r\n4.0 Troubleshooting\r\n------------\r\n\r\nIf you are using V1.0.0 then the examples above won't work for you. It is reccommend that you upgrade to the latest version.\r\n\r\nLook at the response class (JonnyW\\PhantomJs\\Response) to see what data you have access to.\r\n\r\nAn explanation of the errors that are thrown by the client:\r\n\r\n### CommandFailedException\r\n\r\nThe command sent to the PhantomJS executable failed. This should be very rare and is probably my fault if this happens (sorry).\r\n\r\n### InvalidUrlException\r\n\r\nThe URL you are providing is an invalid format. It is very loose verification.\r\n\r\n### InvalidMethodException\r\n\r\nThe request method you are providing is invalid.\r\n\r\n### NoPhantomJsException\r\n\r\nThe PhantomJS executable cannot be found or it is not executable. Check the path and permissions.\r\n\r\n### NotWriteableException\r\n\r\nThe screen capture location you provided or your /tmp folder are not writeable. The /tmp folder is used to temporarily write the scripts that PhantomJS executes. They are deleted after execution or on failure.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}