I think my php scripts times out

Discussion in 'PHP' started by alexts, Aug 14, 2007.

  1. #1
    Hi,

    I have a php script that processes large text file 11mb line by line and outputs it on the screen.

    For some reason,my script just stops after certain period of time.

    I already did set_time_limit(0)

    Is there anything else I need to do to extend execution of my script?
    I host at godaddy.
    Does godaddy puts some kind of limitation on php script execution?

    Thanks a lot for your help guys.
     
    alexts, Aug 14, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Maybe the memory limit. Try increasing it:
    
    ini_set('memory_limit', '25M');
    
    PHP:
    Place also these 2 lines on top of your code to see if there are any hidden errors:
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
     
    nico_swd, Aug 14, 2007 IP
  3. Wildhoney

    Wildhoney Active Member

    Messages:
    192
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    It could also be the Apache timeout as opposed to the PHP timeout.
     
    Wildhoney, Aug 14, 2007 IP
  4. alexts

    alexts Well-Known Member

    Messages:
    1,126
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    Digital Goods:
    1
    #4
    Thank you for you reply guys.

    If it is Apache timeout,is there any way to override it?
    I host at Godaddy Linux hosting.
     
    alexts, Aug 15, 2007 IP
  5. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you're hitting timeouts, it's probably more an indication that your script needs writing more efficiently rather than indicating the timeout is set too low.

    If you're just outputting the file line by line, why do you need a script?

    And surely no one is going to look through 11mb of browser page?
     
    ecentricNick, Aug 15, 2007 IP
  6. Wildhoney

    Wildhoney Active Member

    Messages:
    192
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Not really. It's there for a purpose. If anything is being processed for longer than 30 seconds, then I think you need to re-evaluate what you are trying to do.
     
    Wildhoney, Aug 15, 2007 IP
  7. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Not true. Most scripts I write requires hours or days of continuous work.

    It all depends on the data you are working with.

    Follow these two steps:

    Increase the timeout variables in php.ini.
    Run the script from command prompt rather than the browser.

    Peace,
     
    Barti1987, Aug 15, 2007 IP
  8. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Whilst its true that you need to evaluate it on a case by case basis - I still think that if it takes an age to run in PHP then PHP is probably the wrong tool for the job!

    For a start, if you run it from the command line, rather than through a browser, why bother using a web server and web publishing language such as PHP to do it? Wouldn't the task be better accomplished through a 'nix shell script? Or maybe in a different language such as Java?

    Even if there are core parts that PHP makes real easy (for example, let's say you have a million images that you want to thumbail using GD), I'd still write the majority of that in shell script and just call a php script to do each individual resize rather than expecting my PHP script to stay running for hours and hours.

    Besides, as the poster stated, all he appears to be doing is dumping an 11mb file and unless there is some other processing going on, that sounds a crazy waste of PHP.
     
    ecentricNick, Aug 15, 2007 IP
  9. lwbbs

    lwbbs Well-Known Member

    Messages:
    331
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #9
    Maybe the server kills the process for a limited time, such as 1 hour or somting. I know NetFirms has this limitation. I don't know if GoDaddy has the limitation too. You may contact with GoDaddy to confirm it. If GoDaddy doesn't have, it should be your setting issue.

     
    lwbbs, Aug 15, 2007 IP