Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a php sript with a simple mysql SELECT query which fetches more than 1000 rows from the database...

It gives a 500 internal server error many times when I have a large number of rows to fetch..

The same script works fine when I run it from unix shell command:

/usr/bin/php  scriptname.php

It's a server with apache + php fcgi.

Please help -- thanks!

share|improve this question
1  
Have a look at your apache error log. It will contain more information about the problem. Update your question with what you find. –  Iain Jan 13 '11 at 11:59
    
How is PHP configured? CGI/FastCGI/mod_php? –  Reece45 Jan 13 '11 at 14:22
    
php configured with fastcgi ... –  Amit Aggarwal Jan 13 '11 at 20:28
add comment

4 Answers 4

up vote 0 down vote accepted

I think you're probably hitting the Fcgi timeout. How long does the script take to run? What does Apache's error_log say? Have you tried changing the FcgidBusyTimeout Directive in the Apache config?

share|improve this answer
    
hey, many thanks for the solution. it worked :) –  Amit Aggarwal Jan 15 '11 at 11:28
    
Glad I could help! –  Josh Jan 15 '11 at 15:39
add comment

Probably your script exceeds timeout limit. You should use set_time_limit function.

share|improve this answer
1  
I don't think so, if limit is reached, error is printed if allowed, but it never returned 500 - Internal server error to me, seems like apache issue. –  Ency Jan 13 '11 at 14:09
add comment

How about changing your script, just returning a part of the rows (e.g. 1st 100 rows) and then giving the possibility to fetch the next ones.

Not every problem can be fixed with some configuration parameters.

share|improve this answer
add comment

This can be due to several issues, PHP has different controls to avoid an script to go crazy (max memory and max execution time).

The 3 most common problems associated with a 50x error from your server are

  • Script has timeouted its maximum execution time : You'll see this one because it'll take a long time to reply, one way to avoid this is to override the max execution time in the first line of the script if you know that it'll actually take more than the default max execution
  • Script has used all the available memory : This one will be a lot quicker and possibly it'll be your one, it can be also overriden in case your script needs it
  • Infinite recursive loop : This will be quite violent, and it's the last scenario, normally it's either of the first two, so if neither solution works it's a likely scenario

Good luck with your debugging!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.