Ben bu kodu çalıştırdığınızda Bazen bir süreç ve kimliği almak ve bazen komut yürütmek ancak veri dönüş boş kalır? Herkes akışı düzgün yakalamak için nasıl biliyor mu?
/**
* Run command in background and returns the process id
*
* @param string $cmd
* @return int process id
*/
public function runBackground($cmd)
{
$cmd = $cmd." > /dev/null & echo $!";
if (!($stream = ssh2_exec($this->_connection, $cmd ))) {
return "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
return (int)$data;
}
}