douyuan6490 2011-07-06 10:08
浏览 86

shell_exec - 记录和输出

I am running multiple shell_exec, process.php's run in the background

On the shell/ssh, I execute the code like this: username [~/public_html/curl]# php index.php

Example....

index.php

<?php
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
?>

process.php

<?php
$section = rand(999,999999);
$z = 1;
print "STARTED .... 
";
while($z <= 10) {
 print "---------------------------------
";
 print $section . ": " . $z . "
";
 $z++;
 sleep(2);
}
print "LOOP FINISH at " . time();
?>

when process.php's is running, I am having two problems with this:

  1. I cant not see the output from process.php's (I need to know what they are doing)
  2. I need to know which process is finish and which have started.

What the best way logging the output in real time? saving into text file? or how can it be done to mysql database (logs table)?

  • 写回答

1条回答 默认 最新

  • dqg63264 2011-07-06 10:15
    关注

    If your processes will be alive only within the lifetime of another php script, you could use popen instead of shell_exec:

    http://us.php.net/popen

    This gives you a very convenient way to get data from the other processes into your php script, using the same interface as file handles. To know then the process is done, you could make sure the process sends an EOF (end-of-file) when it's done, and use the feof php function to detect it.

    On the other hand, if your processes may live longer than any other php scripts that talk to it, then a text file may be a very practical solution. Keep in mind, though, that disk access is always much much slower than memory access, so if you use text files for communication, it will not be optimally fast.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料