jonnnnyw / php-phantomjs

Execute PhantomJS commands through PHP
MIT License
1.44k stars 432 forks source link

Null on response! #261

Open tomhapbia opened 6 years ago

tomhapbia commented 6 years ago

I am using this code and my response has it's structure but all the key values are null. Any clue on what would cause this? I run on Mac OS, i have done upx -d /path/to/phantomjs but still do not work.

`<?php require '/vendor/autoload.php';

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

$client->getEngine()->setPath('/bin/phantomjs');
$client->getEngine()->debug(true);

/** 
 * @see JonnyW\PhantomJs\Http\Request
 **/
$request  = $client->getMessageFactory()->createRequest();
$response = $client->getMessageFactory()->createResponse();

$request->setMethod('GET');
$request->setUrl('https://www.google.com/');

$client->send($request, $response);
var_dump($response);
die();

if($response->getStatus() === 200) {
    echo $response->getContent();
}

?>`

and my response look like:

object(JonnyW\PhantomJs\Http\Response)#159 (9) { ["headers"]=> array(0) { } ["status"]=> NULL ["content"]=> NULL ["contentType"]=> NULL ["url"]=> NULL ["redirectURL"]=> NULL ["time"]=> NULL ["console"]=> NULL ["cookies"]=> NULL }

askme-gpt commented 6 years ago

I got the same issue .hope someone to help .

$client = Client::getInstance();
        $client->getEngine()->setPath('D:\\Program Files (x86)\\phantomjs-2.1.1-windows\bin\\phantomjs.exe');
        $client->getEngine()->debug(true);

        $width = 800;
        $height = 600;
        $top = 0;
        $left = 0;

        /**
         * @see JonnyW\PhantomJs\Http\CaptureRequest
         **/
        $request = $client->getMessageFactory()->createCaptureRequest('https://www.51kid.com/', 'GET');
        $request->setOutputFile('D:/phpStudy/WWW/little-feature/storage/app/public/file.jpg');
        $request->setViewportSize($width, $height);
        $request->setCaptureDimensions($width, $height, $top, $left);

        /**
         * @see JonnyW\PhantomJs\Http\Response
         **/
        $response = $client->getMessageFactory()->createResponse();

        // Send the request
        dd($client->send($request, $response), $request, $response);

image

askme-gpt commented 6 years ago

@tomhapbia hey,I have sovled this problem . we need to specilize the file path and phantomjs bin path .

  $client = Client::getInstance();
        $client->getEngine()->setPath('/www/video/bin/phantomjs');
        $client->getEngine()->debug(true);

        $width = 800;
        $height = 600;
        $top = 0;
        $left = 0;

        /**
         * @see JonnyW\PhantomJs\Http\CaptureRequest
         **/
        $name = uniqid();
        $storage_path = storage_path('public/capture/' . $name . 'jpg');
        $request = $client->getMessageFactory()->createCaptureRequest('https://www.51kid.com/', 'GET');
        $request->setOutputFile($storage_path);
        $request->setViewportSize($width, $height);
        $request->setCaptureDimensions($width, $height, $top, $left);

        /**
         * @see JonnyW\PhantomJs\Http\Response
         **/
        $response = $client->getMessageFactory()->createResponse();

        // Send the request
        dd($client->send($request, $response), $request, $response);
d2x commented 5 years ago

The empty object referenced by @tomhapbia is because PhantomJS is failing to run.

Likely because of this: https://github.com/ariya/phantomjs/issues/10904

Try sudo apt-get install libfontconfig