I'm trying to figure out how to pause a function for 2 sec but the rest of the page should run and finish. Is this possible?
I have tried this but with no luck.
echo 'Run this first';
echo 'I am delayed...';
echo 'This should come before the function?!';
Thanks in advance...
I'm using a script to store some data in my sql database and then creating xml documents from that... I need the script to tell/pretend another script it is finished when the first part is over and then run the xml thing...
That is not how PHP works.
What you should do...is not be dependent on such a feature. Why do you need the script to skip that part?
Sounds pretty straight forward to me
Maybe you're looking to have a cron job make any new xml docs later on. That would just be a separate thing. Store the data and be done. Then a second script will run periodically - finding any data it hasn't processed yet and making the xml.
as QMonkey said.
You're not wanting a 2 second pause, you're wanting normal program execution. do A, then B when you're done with A, then C when you're done with B.
PHP does not do asynchronous execution unless you're using fork/exec (IE: Something outside of the script)
Does the xml function need to output anything?
The phrase you are looking for is "asynchronous execution". Parts of PHP support async operations, most of it doesn't, and the parts that do won't function exactly the same on every host.
It is in your user's best interest to not throw arbitrary delays into code. PHP also has an execution time limit when running on a web host. When PHP runs from the command-line (e.g. via a cron job), there generally is no time limit. This seems like one of those things best left to a long-running cron script to process. Write a temporary file that indicates that the cron script needs to check the database. The cron script checks for that file's existence every second (PHP has some nuisance issues here - see clearstatcache()) - if so, it runs the SQL query looking for what needs processing, does the processing, and then updates the database to indicate that it is done. Of course, you said there is an XML file that is generated, so you can just check to see if it exists at that point.
This topic is now closed. New replies are no longer allowed.