SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is sleep() the way to go?

    I've got a simple script that runs off a database with about 8,000 records that basically runs the script for every record to send a message - similar to an email script.

    As the database grows I'm starting to creep up on my max execution time and the script times out every once in a while.

    A friend suggested that I use php's sleep() function every 1,000 or so. Will this allow my script to run without maxing out or is it just adding to the scripts total execution time?

    If you don't suggest sleep I could always store the last record sent in the database - reload script - then continue over and over until I've completed sending the messages.

    Hope this isn't to confusing.

    ** I realize I can change the ini settings which I've already done but don't wish to completely max this level out as it's not needed anywhere else.

    Thanks
    jw

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set_time_limit

    If you're using PHP's mail function to send these messages, I'd suggest you do sleep() every 1,000 or so to reduce the load you're placing on the SMTP server. Alternatively, swiftmailer comes very highly recommended on these forums, although I've not used it myself - I suggest Googling for it if you want to learn more.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's actually not a mail thing - I have to pass an xml string to a 3rd party server one by one based on which names / numbers are in my database.

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, well then you probably don't need sleep. set_time_limit(0) at the beginning of your script will prevent your script from timing out though; you were correct in thinking that sleep would merely add to your script's execution time and not in fact raise this limit.
    PHP questions? RTFM
    MySQL questions? RTFM

  5. #5
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great. thanks kromey!


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
  •