【问题标题】:how exec a cmd command that run log time如何执行运行日志时间的cmd命令
【发布时间】:2014-01-09 13:57:04
【问题描述】:

当我使用 phantomjs 制作服务器时,该服务器会侦听某个端口,该文件会长时间打开。 我将此代码用于使用 php 执行 phantomjs :

exec('phantomjs server.js');

ans 例如 phantomjs 服务器文件是

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

因为 phantomjs 服务器长时间应答并退出,我无法运行 exec 行下方的其他代码。

有什么办法可以从php很好地运行它..?


问题解决方法:

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

【问题讨论】:

    标签: php phantomjs shell-exec


    【解决方案1】:

    您可以在后台运行脚本。但是你失去了对过程的控制。

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

    您也可以使用 beanstalk / Gearman 之类的东西来分隔这两个进程。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    相关资源
    最近更新 更多