1

I am not sure if I have totally missed something here so I am asking, to hopefully become a better person. So I already now, ask for forgiveness for my stupidity, if any.

I have a client that is hosted by company that now is blaming the website I've build for the client, for "crashing" (or at least making it run very slow) the server over and over again. And no this is not a huge website with any complex script. It is a blog, with comment functions.

They tell me this is the problem, because from logs there seems to be only one problem:

www.xxxxxx.se xxx.xxx.xx.xxx [14/Mar/2011:05:08:02 +0100] fcgi_php_error:PHP Warning: mysql_query() [function.mysql-query]: Unable to save result set in /home/t/xxxxx/www/include/php/newsfeed_full.php on line 66, PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/t/xxxxx/www/include/php/newsfeed_full.php on line 68

Line 66:

$sql = "INSERT INTO `newsfeed_comments` (post_id, reply_id, date, name, text) VALUES ('".mysql_real_escape_string($post_id)."', '".mysql_real_escape_string($_POST['reply_id'])."', '".date('YmdHis')."', '".mysql_real_escape_string($_POST['name'])."', '".mysql_real_escape_string($_POST['text'])."')";
mysql_query($sql) or die(mysql_error());

$sql output:

INSERT INTO `newsfeed_comments` (post_id, reply_id, date, name, text) VALUES ('168', '111194', '20110322145339', 'Test 2', 'Test text 2')

Line 68:

$sql = "SELECT * FROM `newsfeed_comments` WHERE `post_id` = '".$post_id."' && `reply_id` IS NULL ORDER BY `date` DESC";
$result = mysql_query($sql);
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
//and so on...

$sql output:

SELECT * FROM `newsfeed_comments` WHERE `post_id` = '168' && `reply_id` IS NULL ORDER BY `date` DESC

Problem is that, I have never seen these error myself from testing. I have never been able to replicate the errors, in any way. So it is obviously working.

My question is, what could be wrong? The hosting company just tells me that I need to make sure my script can handle all the possible errors their server might give out.

Same script runs flawlessly on 10-15 other hosting services without any problems and I have never had any problems with them.

Am I missing anything crucial? Do I have a large knowledge gap when it comes to PHP?

6
  • fcgi_php_error:PHP Warning: mysql_query() [function.mysql-query]: Unable to save result set this sounds very weird and I would be surprised if it's your script's fault. Interested to see what comes up Commented Mar 22, 2011 at 13:17
  • 1
    Can you post the output of $sql in order to see how php solves your variables? Moreover if you want to store current datetime you can use now() mysql function. Commented Mar 22, 2011 at 13:21
  • Googling "unable to save result set" seems to suggest it is caused by corrupt tables or by hitting memory limits. Commented Mar 22, 2011 at 13:24
  • how does one get corrupt tables? and to prevent it? Commented Mar 22, 2011 at 13:40
  • 1
    I don't know. You might be better off asking on serverfault.com. Commented Mar 22, 2011 at 13:47

4 Answers 4

1

Possibly its a memory allocation error. Could you reboot your MySQL server instance?

Sign up to request clarification or add additional context in comments.

Comments

1

Perhaps he has WARNINGS turned on on his machine, this aren´t errors, php tells you some Warnings. See http://php.net/manual/en/function.error-reporting.php

1 Comment

They are retrieving the error from logs, it doesn't have anything to do with error reporting.
0

You can handle the error and do some debugging by wrapping the while loop in an if ($result) statement. Check your script's memory usage with memory_get_usage() and your memory limit with ini_get('memory_limit');

$sql = "SELECT * FROM `newsfeed_comments` WHERE `post_id` = '".$post_id."' && `reply_id` IS NULL ORDER BY `date` DESC";
echo "Memory limit: " . ini_get('memory_limit');
echo memory_get_usage();
$result = mysql_query($sql);
echo memory_get_usage();
if ($result) {
  $i = 0;
  while ($row = mysql_fetch_assoc($result)) {
    ...
  }
}

Comments

0

This error is common when a table is corrupted. You should try "repairing" the table either using phpMyAdmin under the Operations tab or I believe you can run a query like "repair table newsfeed_comments".

or

Maybe there is an edge case where the sql statement you build is invalid. Try capturing the error on screen or log file.

$sql = "SELECT * FROM `newsfeed_comments` WHERE `post_id` = '".$post_id."' && `reply_id` IS NULL ORDER BY `date` DESC";
$result = mysql_query($sql) or error_log(mysql_error());

4 Comments

I will try this, but shouldn't this error be frequent then? I myself have never been able to break or get any error while server is "working", but these error are from an error log. And is it my fault that the table is broken? and how do I prevent this from happening? What bothers me is that this hosting company blames all on me, and I have never ever had any problem with any hosting company before.
How often is the error showing in the log? If tables are regularly being corrupted it is probably a hardware or installation issue.
Every 1-20 min there seems to be an error logged, some times up to 20 error in 1 min, exact same error. I am even surprised that there would be that many visitors, I doubt it.
I have tried to repair all the tables now and it still looks like I have same problem. Is this even my problem or is it the hosting company's?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.