I am having a problem with the following script, it only writes in the database the first PID number but it executes both commands:
<?php
error_reporting(0);
include_once "config/mysql.php";
// the path
$path = "PATH=$PATH:/share/MD0_DATA/.qpkg/Optware/bin:";
//random number for the log file name
$random = rand(1,500000);
//initial download location
$init_loc="/share/MD0_DATA/Qdownload/plowshare";
$items = rtrim($_POST['items'],",");
$sql = mysql_query("SELECT url FROM plow WHERE id IN ($items)") or die ('Error: ' . mysql_error());
$db_row = mysql_fetch_assoc($sql);
foreach ($db_row as $value) {
//random number for the log file name
$random = rand(1,500000);
//log file name
$out_file = '/share/MD0_DATA/Qdownload/plowshare/Logs/log'.$random.'.txt';
//command 1
$command = exec("($path" . " nohup /opt/bin/plowdown -o '$init_loc' " . "'$value' 2> " . "'$out_file' > /dev/null &);" . "echo $$;", $out);
exec($command, $out);
$query = mysql_query("UPDATE plow SET state = 'Active', pid = '$out[0]' WHERE id IN ($items)") or die ('Error: ' . mysql_error());
}
mysql_close();
?>
$items comes from a multiselection I make in flexigrid.
LE: If I run this command thru Putty:
nohup /opt/bin/plowdown -o /share/Qdownload/plowshare http://www.megadownloadlink.com 2> /share/Qdownload/plowshare/Logs/log342342.txt > /dev/null &
I get the PID number of that process PLOWDOWN, I can see this in my process list with TOP.
so I need to a run the command for every URL that is selected and input the PID number in the database in case I want to stop the process later on.
Hope this makes sense.
error_reporting(0);is the root of all your problem. Should be at leastE_ALL, not zero.