MFD3000
MFD3000

Reputation: 874

Running PhantomJS as daemon in OS X

I am using Zend framework and phantomJS to render images for a site I work on. I have a job listener script that loops and looks for jobs in a queue. Upon finding a job, it uses data from the job message to construct a phantomJS command and executes the command via php's EXEC command.

This process works great if I start the job listener myself from the command line. However if the daemon user (web user in OS X) attempts to run phantomJS, nothing happens. No error message, nothing.

I have tried several things including
1. adding this line to sudoers daemon ALL=NOPASSWD: /usr/bin/phantomjs
2. giving phantomjs and its parent directory 777 permissions.
3. giving daemon ownership of phantomjs

However, despite all of this, I cannot get execute phantomJS from Daemon user.

If anyone can point me in the right direction or add some suggestions, I would be very appreciative.

Thanks in advance,

Dan

Upvotes: 1

Views: 1335

Answers (1)

Hemerson Varela
Hemerson Varela

Reputation: 25802

You could try run your phantomjs script like a service instead of run it by EXEC command.

Using an embedded web server module called Mongoose, PhantomJS script can start a web server. This is intended for ease of communication between PhantomJS scripts and the outside world and is not recommended for use as a general production server.

For information about how works the embedded web server see here

Here an example about how a PhantomJS script can start a web server.

var server = require('webserver').create();
var service = server.listen('127.0.0.1:8080', function(request, response) {
    response.statusCode = 200;
    response.write('<html><body>Hello!</body></html>');
    response.close();
});

After the services is running, it can send as response a JSON Object which can be easily interpreted by PHP.

To listen to ANY domain server.listen('8080', ....)

set HTTP response headers response.setHeader("Access-Control-Allow-Origin","*");

Upvotes: 2

Related Questions