0

I'm trying to create a form just to mess around with and I there are two sections of this form. The first input is a number to count up to and the second input is a delay interval in seconds.

I have two ways of doing this. One, is to do this client side and the other is to take the variables and send them via php. This will allow the user to leave the website and have the script still working.

The issue with this being server side is that after 60 seconds, the PHP script stops working. The form is being sent via AJAX. Here is my PHP code. I'm also on shared hosting and do not have the ability to edit PHP.ini.

$amount = $_POST["amount"];
$time = $_POST["time"];
date_default_timezone_set('America/Los_Angeles');
$x = 0;
while($x < $amount) {
    echo $x;
    $x++;
    sleep($time);
} 
echo ("Counted to " . $x); 

2 Answers 2

2

You can use max execution time on your php file, add this line in your php file.

ini_set('max_execution_time', 300); //300 seconds = 5 minutes
Sign up to request clarification or add additional context in comments.

2 Comments

I put that in right below date_default_timezone_set('America/Los_Angeles'); and I got an error in the console saying... i.imgur.com/S03ZOTU.png
Your are using nginx server or apache/httpd server?
0

You can use set_time_limit to set the max execution time, and 0 means no time limit (not recommanded for cgi, since you web server, apache/iis still have a time limit)

and if you want to change your execution time limit of all the php scripts, you can change the setting max_execution_time in the php.ini

3 Comments

I put ini_set('max_execution_time', 300); in my script and I got an error i.imgur.com/S03ZOTU.png
@pshyoulost , as I mentioned in my answer, your web server will still have a time limit for your script.
@pshyoulost , it depends. If you can modifiy the setting of your web server, of course you can fix it, otherwise you need to contact the tech support.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.