php-phantomjs
php-phantomjs copied to clipboard
Not stable , getting status 408 and null content
Hello there,
Thanks for your great effort to make this project real.However, I am getting random errors which I can not figure out why and I hope someone can help.
The script is workng fine for google.com , but when I try to get with other websites it start through errors and retruning status 408 .Some time I get the status 200 but the content to NULL if I try to get an xml file in this url , any advices ?! One more thing when I uncomment the debug line the script hangout , how I can echo the debug the right way ?!
Here is my code
<?php
require_once __DIR__ . '/vendor/autoload.php';
use JonnyW\PhantomJs\Client;
if ($_GET) {
$link = $_GET['link'];
} else {
$link = $argv[1];
}
if (! empty($link) ) {
$client = Client::getInstance();
$client->getProcedureCompiler()->disableCache();
$client->getEngine()->setPath('C:/scripts/bin/phantomjs.exe');
//$client->getEngine()->debug(true);
$client->getEngine()->addOption('--load-images=true');
$client->isLazy(); // Tells the client to wait for all resources before rendering
$request = $client->getMessageFactory()->createRequest($link, 'GET');
//$request->setTimeout(5000);
$response = $client->getMessageFactory()->createResponse();
// Send the request
$client->send($request, $response);
$return['Status'] = $response->getStatus();
$return['Link'] = $link;
$return['Content'] = $response->getContent();
//$return['Log'] = $client->getLog();
echo json_encode($return, JSON_PRETTY_PRINT);
}
Hi,
I've got the same error when trying to generate a PDF from a local URL. Maybe a phantom.js bug? http://stackoverflow.com/questions/35739174/phantomjs-408-error-socket-operation-timed-out
I am facing same issue, it always returns status code 408 for any site, if you guys had fixed, please help me
This works for me in the same situation: $client->getEngine()->addOption('--load-images=false');
$request->addHeader("User-Agent", "Your Application Name");
I have tried it and it working form me!
Just stumbled upon the same issue. What worked for me was simply setting a longer timeout. Especially if you are iterating over multiple pages or your web server is under some strain due to db calls or similar.
$request->setTimeout(20000); // 20 seconds
It is amazing that a post from 2017 still get replies!
It is amazing that a post from 2017 still get replies!
Yeah true that. Been using PhantomJS forever and its never let me down :)