我需要运行一个casperJS脚本,通过PHP从Gearman启动。当我从CLI启动Gearman工作时,所有工作都很精彩。但是如果我通过supervisord之类的东西自动启动Gearman工作器,casperJS将导致PhantomJS无限地挂起99%的CPU。即使是一个简单的'casperjs --version'也会导致PhantomJS挂起 - 但只有从任何地方启动时才会出现这样的情况:/usr/bin/php /var/www/xmweb/gearman_client_tests/casperTest.php
这一切都发生在运行Debian Wheezy的流浪汉上。
我正在寻找任何地方来解决为什么PHPs / Gearmans产生的casperJS只能在从CLI调用时才能工作;为什么完全挂起幻影?如果它是一个权限或环境的东西,为什么“phantomjs --version”工作但不是“casperjs --version”?
<?php
/**
* The Gearman Worker script
*/
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("LayoutbooksAssembler", "sendToCasper");
while ($worker->work());
function sendToCasper($job) {
echo "whoami you ask? ";
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
echo "!\r\n\r\n";
$jobParams = (array) json_decode($job->workload());
exec("phantomjs --version",$output);
var_dump($output); //got the phantomjs version (2.1)
//everything thus far is rendered to screen or logged just finewhen worker is initiated via CLI *or* supervisord
//but if started from supervisord, the casperjs process below hangs (phantomjs takes 99% CPU until killed) and nothing in a casper script runs
exec("casperjs --version",$moreOutput)
var_dump($moreOutput); //will never get here if gearman worker is started from anything but CLI
}
supervisord.conf:
[program:casperWorker]
command=/usr/bin/php /var/www/xmweb/gearman_client_tests/casperTest.php
process_name=casperWorker
numprocs=1
user=vagrant
environment=GEARMAN_USER="vagrant"
stopsignal=KILL
autostart=true
autorestart=true
stdout_logfile=/home/vagrant/gearmanLogs/casper.log
stderr_logfile=/home/vagrant/gearmanLogs/casper_errors.log
如果通过直接网址(noProb.php)调用,这样可以正常工作:
<?php
exec("casperjs --version",$newOutput);
var_dump($newOutput);