SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Amsterdam, NL, and France
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
        <?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
    * * * * My site * * * *
    * * * * My paintings * * * *

  2. #2
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
        <?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);
                     }
            }
        
    ?>

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Your if statement is wrong:

    PHP Code:
    if $counter $last
            

    Should be:

    PHP Code:
    if($counter == $last
            { 
    Hopefully that'll solve the problem.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Amsterdam, NL, and France
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quel stupide.

    Thanks.
    * * * * My site * * * *
    * * * * My paintings * * * *

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:


    Instead of $last = $last + 20; you can use $last += 20;, it's shorter
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Amsterdam, NL, and France
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    * * * * My site * * * *
    * * * * My paintings * * * *

  7. #7
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP: Runtime Configuration - Manual

    If you're using a cron-job you shouldn't have this problem; for testing use set_time_limit(0).
    Last edited by GOPalmer; Jun 22, 2011 at 09:32. Reason: spelling :)

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Amsterdam, NL, and France
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone for your contributions and help. The problem has gone away as I don't need the pause anymore. Mike
    * * * * My site * * * *
    * * * * My paintings * * * *


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •