0

私はこれにしばらく時間を費やしましたが、これを機能させることができません。以前にこれについていくらか関連する質問をしましたが、質問を絞り込むためにさらに調査を行うことができるように削除したため、申し訳ありません。この時点で私は立ち往生しています。これで解決策があると思ったのですが、期待どおりに機能しませんでした。誰かが同様の質問をし、以下のようなコードを提供するフォーラムを見つけました。これは私が試しています。スクリプトは実行されますが、それでもPHPコードの次の行に進む前に、それが終了するのを待ちます

    proc_close(proc_open ("/var/www/other_scripts/perl/apps/emails_extract_from_url.pl \"$stoopid\"", array(), $foo));
4

3 に答える 3

3

ねえ、私は最近proc_openをたくさん使っています、そしてそれは次に進む前にそれが終わるのを決して待ちません。空のarray()を使用するだけでなく、パイプを指定するようにしてください

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

また、proc_openを変数に割り当てます。

$myProc = proc_open("/var/www/other_scripts/perl/apps/emails_extract_from_url.pl \"$stoopid\"", $descriptorspec , $foo)

次に、を使用してプロセスのステータスを取得できます。proc_get_status($myProc);

詳細はこちらhttp://au.php.net/proc_open

クロージングに関する詳細情報。

$temp = fgets($this->open_pipes[$thread_id][1], 1024);
if($this->checkFinishedThread($thread_id))
{
    fclose($this->open_pipes[$thread_id][1]);
    proc_close($thread);
}

function checkFinishedThread($thread_id)
{
    $test = stream_get_meta_data($this->open_pipes[$thread_id][1]);
    if($test['eof'] == 1)
        return true;
    return false;
}
于 2010-08-06T04:22:02.117 に答える
0

proc_openで遊んだときのコードの一部は、
proc_close(10〜30秒)で問題が発生したため、Linuxコマンドkillを使用してプロセスを強制終了しました。



$options=array();
$option['sleep-after-destroy']=0;
$option['sleep-after-create']=0;
$option['age-max']=40;
$option['dir-run']=dirname(__FILE__);
$option['step-sleep']=1;
$option['workers-max']=(int)file_get_contents($maxworkers_file);
$option['destroy-forcefull']=1;

$workers=array();

function endAWorker($i,$cansleep=true) {
        global $workers;
        global $option;
        global $child_time_limit;
        if(isset($workers[$i])) {
                @doE('Ending worker [['.$i.']]'."\n");
                if($option['destroy-forcefull']==1) {
                        $x=exec('ps x | grep "php check_working_child.php '.$i.' '.$child_time_limit.'" | grep -v "grep" | grep -v "sh -c"');
                        echo 'pscomm> '.$x."\n";
                        $x=explode(' ',trim(str_replace("\t",' ',$x)));
                        //print_r($x);
                        if(is_numeric($x[0])) {
                                $c='kill -9 '.$x[0];
                                echo 'killcommand> '.$c."\n";
                                $x=exec($c);
                        }
                }
                @proc_close($workers[$i]['link']);
                unset($workers[$i]);
        }
        if($cansleep==true) {
                sleep($option['sleep-after-destroy']);
        }
}

function startAWorker($i) {
        global $workers;
        global $option;
        global $child_time_limit;

        $runcommand='php check_working_child.php '.$i.' '.$child_time_limit.' > check_working_child_logs/'.$i.'.normal.log';
        doE('Starting [['.$i.']]: '.$runcommand."\n");
        $workers[$i]=array(
                'desc' => array(
                        0 => array("pipe", "r"),
                        1 => array("pipe", "w"),
                        2 => array("file", 'check_working_child_logs/'.$i.'.error.log', "a")
                        ),
                'pipes'                 => null,
                'link'                  => null,
                'start-time'    => mktime()
                );
        $workers[$i]['link']=proc_open(
                $runcommand,
                $workers[$i]['desc'],
                $workers[$i]['pipes'],
                $option['dir-run']
                );
        sleep($option['sleep-after-create']);
}

function checkAWorker($i) {
        global $workers;
        global $option;
        $temp=proc_get_status($workers[$i]['link']);
        if($temp['running']===false) {
                doE('Worker [['.$i.']] finished'."\n");
                if(is_file('check_working_child_logs/'.$i.'.normal.log') && filesize('check_working_child_logs/'.$i.'.normal.log')>0) {
                        doE('--------'."\n");
                        echo file_get_contents('check_working_child_logs/'.$i.'.normal.log');
                        doE('-------'."\n");
                }
                endAWorker($i);
        } else {
                if($option['age-max']>0) {
                        if($workers[$i]['start-time']+$option['age-max']$v) {
                endAWorker($i,false);
        }
        @doE('Done killing workers.'."\n");
}

register_shutdown_function('endAllWorkers');

while(1) {
        $step++;
        foreach($workers as $index=>$v) {
                checkAWorker($index);
        }
        if(count($workers)==$option['workers-max']) {
        } elseif(count($workers)$option['workers-max']) {
                $wl=array_keys($workers);
                $wl=array_pop($wl);
                doE('Killing worker [['.$wl.']]');
                endAWorker($wl[0]);
        }
}

于 2010-08-06T06:41:22.737 に答える
0

コマンドライン引数の最後にアンペア(&)が必要です。

proc_close(proc_open ("/var/www/other_scripts/perl/apps/emails_extract_from_url.pl \"$stoopid\" & ", array(), $foo)); 
于 2016-02-25T07:29:28.780 に答える