【问题标题】:wget process doesn't stop when php cron endsphp cron结束时wget进程不会停止
【发布时间】:2014-06-24 10:28:57
【问题描述】:

我正在使用以下方式运行我的 cron:

 $command = 'wget -qO- --timeout=0 --tries=1 my_url &';
 $descriptorspec = array(
   0 = > array('pipe', 'w'), // stdin
   1 = > array('pipe', 'w'), // stdout
   2 = > array('pipe', 'w') // stderr
 );
 $proc = proc_open($command, $descriptorspec, $pipes);
 proc_close($proc); 

我必须使用 timeout=0 的原因是 cron 运行的时间范围从几秒到几小时不等。但是我注意到如果 cron 花费的时间超过几分钟,如果我以上述方式运行它,它会一直挂在进程树中(即使工作完成,所以 cron 完成了它的任务)。我试图通过发送来强制它停止:

header("Connection: close"); 
ob_end_flush(); 
ob_flush(); 
flush();

我想要实现的是能够准确地知道进程何时完成,这样我就可以确定它停止是因为它成功了还是因为出现了某种错误。

每个 cron 看起来都类似于:

session_write_close(); 
ignore_user_abort(1);
.... do_the_job .... 
header("Connection: close"); 
ob_end_flush(); 
ob_flush(); 
flush();
exit();

如何强制 wget 死掉?我将不胜感激在这件事上的任何提示。我也试过 curl 没有运气。

【问题讨论】:

    标签: php curl cron wget


    【解决方案1】:

    在我的特殊情况下,我能够通过使用命令运行它来克服问题:

    php5 index.php --uri=controller/method/var1/var2
    

    对于 Kohana 文件,以及

    php5 file_path/file_name.php
    

    对于其他 php 文件。如果我必须从不同的服务器运行文件,此解决方案将不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-16
      • 2021-11-05
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多