Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php, wait 5 seconds before executing an action

Tags:

php

I have a .php script that I use for creating the list of my products. I am on shared hosting, so I can't do a lot of queries otherwise I get a blank page.

This is how I use my script now:

script.php?start=0&end=500&indexOfFile=0  ->> make a product0.txt file with first 500 products  script.php?start=501&end=1000&indexOfFile=1 ->> product1.txt file with another 500 products  script.php?start=1001&end=1500&indexOfFile=2 ->> product2.txt file with last 500 products 

How can I modify the script so it will make all these files automatically, so that I don't have to change each time the link manually?

I would like to click a button which will do this:

make the product0.txt file with the first 500 products

wait 5 seconds

make the product1.txt file with with another 500 products

wait 5 seconds

make the product2.txt file with the last 500 products

like image 263
user849690 Avatar asked Jul 18 '11 09:07

user849690


People also ask

How do you delay a function in PHP?

The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. The sleep( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure.

Does PHP wait for function to finish?

PHP is single-threaded, which means that it executes one instruction at a time before moving on. In other words, PHP naturally waits for a function to finish executing before it continues with the next statement.

How do you call a PHP function after some time?

Using pcntl_alarm... Alternatively, if you have the Process Control support enabled in your build of PHP, you might be able to use pcntl_alarm to call a signal handler after a certain amount of time has elapsed.

How do I stop a PHP script?

How we can use the PHP's exit function to stop the execution of remaining code. exit is usually used right after sending final output to a browser, or to stop a script in case there was an error. When exit is used it will stop code-execution completely and exit PHP.


2 Answers

use:

sleep(NUMBER_OF_SECONDS); 
like image 111
Brian Avatar answered Sep 20 '22 18:09

Brian


before starting your actions, use

 sleep(5); 
like image 34
genesis Avatar answered Sep 19 '22 18:09

genesis