Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 第二层exec不返回线程_Php_Background_Exec - Fatal编程技术网

Php 第二层exec不返回线程

Php 第二层exec不返回线程,php,background,exec,Php,Background,Exec,我将一个脚本分解为两个脚本,这样我就可以让第二个脚本并行运行所有输入,而不是串行运行,这需要很长时间。下面是它被分成两部分的样子。出于某种原因,我没有看到第二个exec(snmpwalk)之后的日志记录 我是为了让第一个exec不返回线程,这样它就可以在后台运行第二个脚本。具体来说,我使用的是hotmail.com网站上Viu pa在该链接上推荐的内容 status_parallel.php: <?php error_reporting(E_ALL ); $cng_ip_array =

我将一个脚本分解为两个脚本,这样我就可以让第二个脚本并行运行所有输入,而不是串行运行,这需要很长时间。下面是它被分成两部分的样子。出于某种原因,我没有看到第二个exec(snmpwalk)之后的日志记录

我是为了让第一个exec不返回线程,这样它就可以在后台运行第二个脚本。具体来说,我使用的是hotmail.com网站上Viu pa在该链接上推荐的内容

status_parallel.php:

<?php
error_reporting(E_ALL ); 
$cng_ip_array = array("1.18.8.78",  "4.13.8.75", "4.13.81.72", "4.18.8.76", "4.18.8.22", "4.18.8.81", "4.18.8.74", "4.18.8.23", "4.18.8.156", "4.18.8.73", "40.18.8.77", "4.18.8.80", "2.19.19.80", ); //these are not real ip's

foreach($cng_ip_array as $ip)
{
    $logFile = "/opt/scripts/catv_monitoring/catv/phperror." . $ip . ".log";
    print "ip: " . $ip . "\n";
    exec("php getStatus.php $ip 2>$logFile >&- <&- >$logFile &"); //http://php.net/manual/en/ref.exec.php
}
?>
我认为第二个exec受到第一个exec输出的影响,我给出了它。我需要让第一个exec允许它运行的进程在后台。第二个exec需要返回并继续代码。知道如何让第二个进程返回吗

更新 我试着换了
exec(“snmpwalk…”,$output)

日志文件显示目录列表,但线程永远不会回来,日志文件也不会显示“已完成状态”。这很重要,因为我需要将snmpwalk结果写入数据库。 例如:

$more phperor..log
嗨08:26:19为ip做snmpwalk,下一个。请稍等。08:26:19
输出结果:
阵列(61){
[0]=>
字符串(18)“ModemData.csv”
[1]=>
字符串(18)“ModemData.sql”
[2]=>
字符串(9)“Keith.txt”
[3]=>
字符串(16)“KeithCompare.php”
...
更新2

我注释掉了“//do things”,我在文件中看到了我的日志记录的结束:

...
shane.file
triad_addresses.good.php
triad_addresses.php
done with status for <ip> 08:44:55
。。。
沙恩档案
triad_addresses.good.php
triad_addresses.php
已完成08:44:55的状态

我将研究“做事”可能出现的问题。…

代码有一个问题,我在这里没有详细说明。当我修复它时,问题消失了

prompt:$ more phperror.<ip>.log
hi <ip> 07:16:25Doing snmpwalk for ip, <ip>, next. Please wait.
prompt:$ ps -elf | grep getStatus
0 S employeeID 29635  3604  0  80   0 -  1597 pipe_w 07:21 pts/0    00:00:00 grep getStatus
`exec("ls",$output)`
echo "output results: \n";
var_dump($output);
$ more phperror.<ip>.log
hi <ip> 08:26:19Doing snmpwalk for ip, <ip>, next. Please wait. 08:26:19
output results:
array(61) {
  [0]=>
  string(18) "ModemData.csv"
  [1]=>
  string(18) "ModemData.sql"
  [2]=>
  string(9) "Keith.txt"
  [3]=>
  string(16) "KeithCompare.php"
...
...
shane.file
triad_addresses.good.php
triad_addresses.php
done with status for <ip> 08:44:55