Forum Moderators: coopster
Are you using an .htaccess file?
Do you have any redirects or rewrites?
Is there anyway the PHP script is initiating a redirect (or something), which creates an infinite loop between the .htaccess and the script or the script and the script itself? (Maybe it's possible to generate a 500 with an inefficient script, or loop, or something, but it's not something I've had happen.)
It is possible that your loop takes longer then you have set, i beleive if you do not have a max execution time set it defaults to 30 seconds, so i would assume that could be your problem.
There is only one place to look first - your error logs. A 500 will be recorded there, no matter where it comes from. I find it odd that you say it doesn't.
Basically any request to a server that does not respond back to the browser - i.e., if the process dies or is killed before returning a response, or outputs to STDOUT before generating appropriate content-type headers - will generate a 500, regardless of the technology.
The only time it won't (that I'm aware of) is a process that is not an http request, such as a cron job. Is it possible this script is calling an external process, and that's what's causing it to die?
If you can't isolate the cause, do this:
<?php
header("content-type:text/html");
echo "HERE";
exit 0;
// rest of your code
?>
The exit is important, you want to know at what point it's dying so don't want to let the script continue. Do that, run it, move it down in your script 50-100 lines (or before, then after, the next function call.) Re run it, keep moving it down through your script until you zero in on the specific area that's causing the 500.
$q2="SELECT * FROM chess_play where id='$gameId' LIMIT 1";
$result2=mysql_query($q2) or die("Could not execute query : $q2." . mysql_error());
while($row=mysql_fetch_array($result2)){
Does anyone spot any problems? Thank you again.
while($row=mysql_fetch_array($result2)){
// delete all this
}
The use of "2" ($q, $q2, $result, $result2) variables leads me to think you might have one loop inside another, is it possible you have one misnamed, or something else that's causing it to crash?
Here is all of the include variables-
$q2="SELECT * FROM chess_play where id='$gameId' LIMIT 1";
$result2=mysql_query($q2) or die("Could not execute query : $q2." . mysql_error());
while($row=mysql_fetch_array($result2)){
Does that line look correct? Thank you for all of your help.
I've now eliminated the error to this line-
while($row=mysql_fetch_array($result2)){.....
Sorry, I don't see an error. Looks fine. Are you sure it's connected to the database? You didn't possibly close the connection somewhere before this code? (Should get an error if it's closed, but still . . . )
An aside, PHP executes inline (generally) so variables will overwrite previous values and even set the data type. Recycling is good. :-)
var $foo = Array ('one','two');
$foo = 3; // re-cast as integer
$foo = 'four'; // now it's a string
echo $foo; // s/b "four"
I hate to say this, but on large scripts (1500+ lines) I've had late nights where I had a syntax error and it still runs without error until it encounters the chunk of code that's causing it. An example is
function some_function () {
echo "blah";
function some_other_function () {
echo "blah too";
}
}
May cause an error as posted (or be valid code) but you get the drift . . . a function nested inside a function when I thought I had two. What I do is create a copy, begin stripping it out until I locate the errant chunk, then eliminate that chunk and rebuild it. Generally this is followed by a <facepalm>, but hopefully that is not the case for you.
...if the process dies or is killed before returning a response, or outputs to STDOUT before generating appropriate content-type headers - will generate a 500 ...
You might also give this a stab.
header("content-type:text/html");
echo "entering loop <br>\n";
while($row=mysql_fetch_array($result2)){
// leave your code as-is
}
echo "exiting loop <br>\n";
exit;
Spread out the test to surround the loop, you might be dying and it may output a clue right there. But if you move the three-line echo/exit before and after, you'll never see it.
(Sorry for the exit 0, Perl and PHP are so similar I often mix them up . . . )
I still suspect something outside of PHP could be effecting the results in some way, but without the code, we're probably all really stumped even more than you are...
What does your server error log say regarding the 500 error?
(The error log should not be confused with the server log file.)
Does the page redirect in anyway?
Does the page include any files at all?
Maybe a 'connection.php' file for DB connections?
If so is it included internally /the/path/to/the/file.php or externally http://www.example.com/?
What exactly is supposed to happen when the page appearing to cause (or causing) the error is loaded?
Does it just 'echo out' the results, or is it included by another page, or...
The list of things we don't know about the situation, file and code just keeps going, so the best answer is probably: Check the Server Error Log file which should tell you more about the 500 error, and then post the error log entries (or a portion to let us have a look) plus the relevant code if you can't resolve the issue based on the error log.
I have now managed to generate a 500 based solely on PHP, but mine had to do with a COOKIE check for login and redirect, where if the COOKIE was not present, the script served the login page rather than the content.
The login page was served to the requested location and the requested location was redirected back to from the cookie setting script after the login was complete.
There was an order of operations error for a certain login string, which, when you logged in as a certain (generic) user, made you attempt to keep logging in even though the COOKIE was set. The login script was also checking for the cookie and redirecting to the correct location if it was set...
The end result was: location requested, login page served, login set, redirected to the originally requested location, login page served, redirected to the originally requested location, login page served, redirected to the originally requested location, and on and on...