SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to prevent timeout during a loop?

    I have a loop that gets the images from a specified folder (user uploads) and then creates thumbnails for them. The problem I've been having lately is that sometimes the script times out before it gets through all of the uploads.

    What command is used in php to tell the script to finish executing one thing and then start executing the next as two seperate processes so that it doesn't time out while executing the loop?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The loop wouldn't start the next execution until it is finished the previous one. You could try changing a couple of the PHP configuration settings at the time of script execution. Add the setting changes about the code you will be using.

    PHP Code:
    set_time_limit(0);
     
    ini_set('max_execution_time''360');

    # this one shouldn't be necessary
     
    ini_set('max_input_time','360');

    # if this done via a form post you will also need
     
    ini_set('upload_max_filesize','5M');
     
    ini_set('post_max_size','5M');
     
    ini_set('memory_limit''100M'); 

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My apologies, I guess I didn't explain myself correctly. What I want to do is figure out a way to make each loop execute as if it's a brand new php page... for instance, in WHM, when you create a new account, each step appears to process seperately. How is that done?

  4. #4
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you're talking about multi-threading. If I recall correctly I don't think this is possible w/ PHP. You might be able to execute a shell script server side when the call is made to perform your desired functions however I'm not sure what your permissions are etc...

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Gold Coast, Australia
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP supports forking into child processes through the use of the pcntl_fork funtion.

    Is this script being called from a web browser? If it is, then you also face browser time-out issues.


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
  •