Start the script by a shell script that runs an endless loop and waits for the process to finish.
Since you also have an endless loop in your PHP script this will only be if your script is stopped.
Next you write the PID of the script into a text file.
You should get the PID with this:
http://php.net/manual/en/function.getmypid.php
Next step is to set up a cronjob that runs every hour.
This cronjob reads the PID .txt file, deletes it and kills the process.
Since the shell script mentioned in the beginning also has an endless lopp it will restart the php process directly.
Example scripts:
Starter Script:
#!/bin/bash
while true
do
php myscript.php > /dev/null
done
save it e.g. as start.sh and set chmod +x to be able to execute it.
Now you can start it with:
nohub ./start.sh &
in .php you do something like this at the beginning:
file_put_contents("/tmp/yourscript.pid", getmypid());
And heres the cron script as bash:
#!/bin/bash
PID=`cat /tmp/yourscript.pid`
rm /tmp/yourscript.pid
kill -9 $PID
you can also to the cron script with php:
<?php
$pid=file_get_contents("/tmp/yourscript.pid");
unlink("/tmp/yourscript.pid");
shell_exec("kill -9 $pid");