Take the 2-minute tour ×

I want to run a PHP file/function that will not stop until it finishes it work. Is there any option for that?

(It will not print any information to the browser, it will make calculations and it will store them on a database.

Note: The Apache server is in my PC.

share|improve this question

4 Answers 4

up vote 4 down vote accepted

Check out, http://php.net/manual/en/function.ignore-user-abort.php

however if apache is restarted it will be reset.

Also check out the max execution time as well

share|improve this answer
+1 - Handy to know –  Aiden Bell Oct 16 '10 at 23:25

PHP typically has an execute time limit, and long running requests will hold onto the HTTP connection.

You will want to add a job to a batch queue and have some worker pick-up the work outside of the HTTP request (via a Cron job perhaps).

Here is a good tutorial by IBM that details the cron method complete with MySQL tables and PHP code. Other options are Messaging/Queuing systems rather than a database.

share|improve this answer

put this statement at the top of the script:


This will make the script run indefinitely.

share|improve this answer

If you're running on Windows (assuming you are), you can use the WindowsShell object to exec the script. This will run the script in the background, without opening a command window on your desktop.

$shell = new COM("WScript.Shell"); 
$cmd = $WshShell->Run("c:\php\cli\php.exe c:\yourscript.php", 0, false);

Under the CLI version of PHP, scripts have no max execution time.

If you just need to run a PHP script and don't care about going through a web browser to get there, just run the script directly, using the CLI version of PHP.

If you're on a UNIX system, use exec(). Same idea.

share|improve this answer

Your Answer


