lejahmie
lejahmie

Reputation: 18253

PHP/MySQL server problem

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?

Upvotes: 1

Views: 689

Answers (4)

Jordan Owens
Jordan Owens

Reputation: 742

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());

Upvotes: 0

sreimer
sreimer

Reputation: 4998

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)) {
    ...
  }
}

Upvotes: 0

biakaveron
biakaveron

Reputation: 5483

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

Upvotes: 1

Tobias
Tobias

Reputation: 7380

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

Upvotes: 1

Related Questions