500 Server error and my php script

Discussion in 'PHP' started by absentx, Apr 5, 2010.

  1. #1
    Okay so I wrote a script that loops through a small bit of code until a certain condition is met.

    I also keep track of the amount of loops with an integer variable and then display the amount of loops once the condition is met.

    The main condition I am trying to meet most likely will take between 300,000 and 1,000,000 loops before it hits.

    Anytime it hits in the 100,000 range, everything works fine and it happens pretty quickly...probably five or six seconds. Anything else though I get the 500 internal server error.

    I assume this is directly related to the super cheap shared hosting I am testing this on? To be able to handle that many calcs do I need to be on a dedicated server? I guess I just need to know what needs to happen whether it be on my side or the server side to be able to handle this kind of loop.

    Thanks!
     
    absentx, Apr 5, 2010 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You may find useful information on your error logs.

    This is just my curiosity .. What is a super cheap shared hosting
     
    nabil_kadimi, Apr 5, 2010 IP
  3. Fervid

    Fervid Well-Known Member

    Messages:
    161
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    120
    #3
    You're probably running out of time because of the server's max_execution_time setting. That will automatically stop any script that continues beyond that value.

    Check your server's error log to find out for sure what the issue is. If it's an execution time problem you may be able to set some of the PHP settings in your .htaccess (depending on your host's settings).

    You can try this in your .htaccess file:
    php_value max_execution_time 30
     
    Fervid, Apr 5, 2010 IP
  4. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay excellent...I thought it was something like that and I will check into it right away.

    nabil: I was just testing this on one of my other sites that just uses $6.99 a month godaddy hosting. I thought maybe there was some type of restrictive setting, but thanks to the replies now I know where to start looking.

    EDIT:

    Actually here is the error log:

    [Mon Apr 5 21:01:19 2010] [error] [client] Premature end of script headers: /var/chroot/home/content/a/b/s/mydirectory/html/pagename.php
     
    Last edited: Apr 5, 2010
    absentx, Apr 5, 2010 IP
  5. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does that error log indicate anything?

    Thanks
     
    absentx, Apr 8, 2010 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    To be honest, 300.000 loops is not something you want to happen unless you are doing some sort of benchmarking.
    I'd say that this has something to do with PHP memory limits
     
    nabil_kadimi, Apr 8, 2010 IP
  7. thecancerus

    thecancerus Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it could be suEXEC problem check out http://encodable.com/suexec_problems which might solve it. note : article uses perl.. but you can neglect that.. just read the part where it talks about apache.
     
    thecancerus, Apr 8, 2010 IP