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);

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

it's not work to windows :( ? is any way for win 7 ?
You might find the answer here stackoverflow.com/questions/5367261/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.