Problem with Sleep command

Hi all,

This test code runs through an array of email addresses with the goal of stopping every 20 rows for 60 seconds.

	<?php
	$counter = 0;
	$last = 21;
	foreach ($all_mails as $mails)
		{		
                 echo $mails['e_mail'],'br /';
                 $counter ++;
                 if $counter = $last
	             {
                     $counter = 0;
	             $last = $last + 20;
	             sleep(60);
	             }
		}
	?>

I get the error:

Parse error: syntax error, unexpected T_VARIABLE, expecting ‘(’ in C:\xampp\htdocs\mail_post.html_2.php on line 26

This is the ‘(’ after the sleep command.

What’s wrong please?

Mike

Off Topic:

Instead of $last = $last + 20; you can use $last += 20;, it’s shorter :slight_smile:


    <?php
    $counter = 0;
    $last = 21;
    foreach ($all_mails as $mails)
        {
                 echo $mails['e_mail'],'br /';
                 $counter ++;
                 if ($counter == $last) //<<<-- fixed if statement
                 {
                     $counter = 0;
                 $last = $last + 20;
                 sleep(60);
                 }
        }
    ?>

Your if statement is wrong:


if $counter = $last
        {

Should be:


if($counter == $last) 
        {

Hopefully that’ll solve the problem.

Quel stupide.

Thanks.

Hi again,
Now that the code’s running it works until the first occurence of the sleep command and then gives this error.
Fatal error:
Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\mikesg_2\mail_system\mail\mail_post.html_2.php on line 30

What now?

Mike

PHP: Runtime Configuration - Manual

If you’re using a cron-job you shouldn’t have this problem; for testing use set_time_limit(0).

Thanks everyone for your contributions and help. The problem has gone away as I don’t need the pause anymore. Mike