netrox netrox - 1 year ago 72
PHP Question

how do you execute a script a second time if the first execution does not succeed?

Here's this idea: A php script sends posted data to a different server. If the server fails to get the posted data, the php script should retry in a few minutes.

How do programmers get the script to be executed again in a few minutes to complete the task if the first try fails?

I want to create a php script that when being notified by a new update or insert by a database, makes a call to a different server and posts data to the server. So, no HTML/CSS/JS are involved. It's completely command line - running in the background. So, what if the first execution fails, how do I time the script to retry again in a few minutes?

eis eis
Answer Source

See at unix command, so you don't need a script running while you're waiting for the right time.

echo "php yourscript.php" | at $TIME

You'd put this at the end of your php script, should the call to the other server fail.

shell_exec('echo "php yourscript.php" | at ' . $moment);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download