SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to prevent timeout on slow scripts?

    Hi There,

    I am looking for some advise.

    I am building a script that once a week runs through a databases and finds matches to specific queries and then emails those matches to an email address (real estate web site).

    My issue is timeout and throttling.

    I have used set_time_limit(0); in the beginning of the script and then used sleep(3); to sleep the script for 3 seconds before redirecting the script to itself (via http) and send the next email.

    The reason for the 3 seconds is that my hosting company requires me to throttle email sending to not slow down the server.

    Anyway... I then invoke the script via cron (with the php command) and it appears to work fine.

    My question is... is there a better or more correct way to do this?

    I am afraid that Apache will somehow see this script calling itself many times and then suspend it thinking that it is an endless loop.
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  2. #2
    SitePoint Zealot musher's Avatar
    Join Date
    Nov 2005
    Location
    Hull, England
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are calling it via the php command (CLI), surely the redirect will not be working, unless you are using fopen?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for replying.

    Hmm... I am not sure. This is a Joomla based web site and I am using the following cron task:

    php /home/sitename/public_html/index2.php option=com_property task=tasktosendoutemails

    And it seems to work just fine

    Then in the script (at the very end - I use the built in Joomla function called mosRedirect() which besides a few error checks uses the following code:
    PHP Code:
    if (headers_sent()) {
      echo 
    "<script>document.location.href='$url';</script>\n";
    } else {
      @
    ob_end_clean(); // clear output buffer
      
    header'HTTP/1.1 301 Moved Permanently' );
      
    header"Location: "$url );

    I then pass the full url as argument into that function.

    But I am after the best practice solution and of course eager to find any loopholes or bugs as well.
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain


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
  •