Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Senior Member
    Join Date
    Aug 2011
    Posts
    227
    Member #
    29153
    Liked
    4 times
    I don't know if this is is in the right category or not.

    I have a php page that is doing a LOT. It runs for almost 2 or 3 minutes then times out without finishing. I set up a cron job to call the page and it does not finish there either. I am using it to pull information from a site that I am selling though an affiliate program. It is going in a reading several pages from that site and pulling out several hundred items for sell and placing them on my site. Actually, saving them in a database and my site pulls them from there.

    Is there a way to keep it from timing out? I'm assuming that is what it is doing since it will not finish. If I skip the first portion, it will continue further down that before. The more I skip, the closer it will come to finishing.

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Depends on your hosting environment... The timeout is specified to keep users from Abusing resources in a shared environment.

    Depending on your host, they may be able to allow and adjust the timeout for you on the server end.

    If its only reading several hundred line items, sounds like you could possible optimize the code...

    I regularly pull a file with close to 5000 records from a remote server, and dump it into a temp table... The most time it takes to run is about 20 seconds.

  4. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    227
    Member #
    29153
    Liked
    4 times
    I have a lot of file_get_contents(); functions in it which seems to be what it taking such a long time. Maybe 15000 of them inside a double loop. One loop runs 20 times with the inbedded loop running 15 times. The whole thing is called 50 times.

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    If you're running in a shared environment, kinda doubt they are going to extend your time out...

    Either a vps or standalone server looks to be an option, you can modify your timeout in the php.ini file.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    set_time_limit(900); <-- Place at the head of your script to increase timeout to 15 minutes (900 seconds).

    You can also set your timeout in your .htaccess file (most hosts allow override of that setting in vHosts), but that will affect your entire site (not a good idea).

    Finally, you can override htaccess env vars in a singe script using ini_set() but for timeouts, the set_time_limit is the way to go.

    php.ini is not the way to go for this, because it will affect every site on the host. For things like timeouts, best to adjust at the script level.

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    By the way, if your grabbing the contents of all those files, you definitely don't want to store them in a persistent variable (e.g. in a huge array of 20,000 items)... you'll exceed your server's memory limit and crash everyone's website. You should do whatever you're doing with each file's contents then unset() it from memory before moving on to the next one (or just reuse the same scalar variable to store the file contents). Also, consider using the SPL DirectoryIterator to increase Filesystem performance with an iterative process.

  8. #7
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Yeah, I should have put that disclaimer in about the php.ini file... That's only if you have your own server... And yours are the only sites on the server.

  9. #8
    Junior Member
    Join Date
    Dec 2012
    Posts
    13
    Member #
    34103
    Liked
    2 times
    Yep, you'd pretty much have to convince the host to increase the timeout in php.ini. Less and less are allowing overide, since it defeats the purpose of securing the server in the first place. After the first mass defacing, you can guarantee that allow overide will be the first thing to go.


Remove Ads

Posting Permissions

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

Search tags for this page

how do i keep my program from timing out

,

how to keep a web page from timing out

Click on a term to search for related topics.
All times are GMT -6. The time now is 10:36 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com