EDIT:
For long running scripts (like daemons) i recommend using popen and stream the content out of the resource.
Example:
<?php
$h = popen('./test.sh', 'r');
while (($read = fread($h, 2096)) ) {
echo $read;
sleep(1);
}
pclose($h);
You should check your php.ini for the "max_execution_time". If you are in a webserver context also check for configured timeouts there.
END OF EDIT
Have you tried exec
The second parameter is a reference to an array which gets filled with the scripts output
in short:
<?php
$output = array();
exec('/path/to/file/helloworld', $output);
file_put_contents('/path/to/file/output.txt', implode("\n", $output));
Example:
test.sh:
#!/bin/bash
echo -e "foo\nbar\nbaz";
echo -e "1\n2\n3";
test.php:
<?php
$output = array();
exec('./test.sh', $output);
var_dump($output);
output:
php test.php
array(6) {
[0]=>
string(3) "foo"
[1]=>
string(3) "bar"
[2]=>
string(3) "baz"
[3]=>
string(1) "1"
[4]=>
string(1) "2"
[5]=>
string(1) "3"
}
Quote of the official php documentation (link see above)
If the output argument is present, then the specified array will be filled with every line of output from the command.