1

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.

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

put this statement at the top of the script:

set_time_limit(0);

This will make the script run indefinitely.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.