【发布时间】: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