PHP + PhantomJS Rasterize

I am using PhantomJS 64 bit in my PHP application to dynamically capture an HTML page to send to the user via email.

phantomjs rasterize.js "http://..." /path_to_images/image.png 

This method works fine when I run the above on the command line, but when the PHP script runs the command using exec , it fails without output and returns exit code 11.

If I switch it to use the phantomJS 32-bit binary, the command will succeed, but will not be able to load Google JSAPI on the page with the Reference Error: can't find variable google error. This is a problem because not all page content is loaded and recorded as an image. JSAPI is enabled using HTTPS. If I switch to HTTP, the reference error will disappear, but the resulting image will turn black.

I tested the command as the same user that php works like.

Summarizing:

 command> phantomjs_64 rasterize.js "http://..." /path_to_images/image.png 

Ok

 exec('phantomjs_64 rasterize.js "http://..." /path_to_images/image.png'); 

No exit, exit code 11

 command> phantomjs rasterize.js "http://..." /path_to_images/image.png exec('phantomjs rasterize.js "http://..." /path_to_images/image.png'); 

Incomplete exit

Does anyone know why, by default, the phantomJS rasterize.js script will fail when launched in PHP, or will there be a workaround for this?

+2
php phantomjs lamp shared-hosting
source share
1 answer

UPDATE: This article is a great article from Arlo Carreon indicating how to make this work on shared HostGator hosting (this was my problem). Just add 2>&1 at the end of the command to redirect the output. The 64-bit version still does not work, but it fixes the 32-bit version.

Turns out this only happens when a PHP script is requested through the Apache web server. The workaround is to create a database entry for users who need to receive an email and configure cron to execute a PHP script that calls PhantomJS for each user entry in the database. When cron is configured to operate at the smallest interval, the user understands that the email was generated and sent immediately.

0
source share

All Articles