0

when i make server with phantomjs that listen for some port this file open for long time . i use this code for excute phantomjs with php :

exec('phantomjs server.js');

ans for example phantomjs server file is

if (system.args.length !== 2) {
    console.log('Usage: server.js <some port>');
    phantom.exit(1);
} else {
    port = system.args[1];
    var listening = server.listen(port, function (request, response) {
        console.log("GOT HTTP REQUEST");
        console.log(JSON.stringify(request, null, 4));

        // we set the headers here
        response.statusCode = 200;
        response.headers = {"Cache": "no-cache", "Content-Type": "text/html"};
        // this is also possible:
        response.setHeader("foo", "bar");
        // now we write the body
        // note: the headers above will now be sent implictly
        response.write("<html><head><title>YES!</title></head>");
        // note: writeBody can be called multiple times
        response.write("<body><p>pretty cool :)</body></html>");
        response.close();
    });

because phantomjs server stay long time to answer and exit from it , i cant run other code that below exec line.

is any way to run it from php well .. ?


Problem Solve With:

$WshShell = new COM("WScript.Shell");
$run_cmd = "cmd c:/xampp/php/php.exe c:/xampp/htdocs/Gashash/batch_test.php";
$WshShell = $WshShell->Run($run_cmd, 0, false);
MOB
  • 853
  • 2
  • 13
  • 28

1 Answers1

1

You could run the script in the background. But you lose control over the process.

exec('phantomjs server.js > /dev/null &');

You could also use something like beanstalk / Gearman to separate the two processes.

tlenss
  • 2,609
  • 2
  • 22
  • 26
  • it's not work to windows :( ? is any way for win 7 ? – MOB Jan 09 '14 at 20:00
  • You might find the answer here http://stackoverflow.com/questions/5367261/php-exec-as-background-process-windows-wampserver-environment – tlenss Jan 09 '14 at 21:04