I would like to execute a command in PHP with exec
.
If i pass the second param $out
and start the script from the command line, it waits until the exec is finished.
But if I launch it from the Browser, the Browser immediately shows the result.
The command executes some unit tests and store the output in a file ($last)
, which I want to display in Browser.
Afterwards a logfile ($logfile
) is created. Then the file from command will be formatted for html print with nl2br()
.
I thought there were some permission problems with the user deamon, but if I give daemon the permissions for my project or the file on /opt/lamp/htdocs/project
the created file is always empty.
exec($command , $out);
date = new DateTime();
$timestamp = $date->format('Y-m-d H:i:s');
$filehandle = fopen($lastlog, 'r');
$filetext = fread($filehandle, filesize($lastlog));
$formattext = nl2br($filetext);
$last = file_put_contents($lastlog, $formattext);
$logfile = file_put_contents($projectdir . 'logs/' . $specfile . '/' . $timestamp . '.txt', $filetext);