Welcome! Log In Create A New Profile

Advanced

Those dumb "MYSQL server has gone away" errors

Posted by fastest963 
Those dumb "MYSQL server has gone away" errors
November 08, 2007 12:02AM
Hate seeing this at the end of your spider...

MySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone away . . . MySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone away

Well I have a mod to fix this

open spiderfuncs.php and at the bottom put...

function mysqltest(){
if (mysql_ping() === FALSE){
while (mysql_ping() === FALSE){
print "<font color = 'red'>Mysql Server Not Avaliable!... </font>";
flush();
sleep(20);
}
}
}



Then search through spiderfuncs.php and spider.php for "mysql_query".

In front of mysql_query(.... put
mysqltest();

You should find over 15 "mysql_query" results (my spider is highly modded so I don't know the exact amount)

You can also look though admin.php but that isn't necessary.

Hope this helps!



Edited 2 time(s). Last edit at 11/08/2007 02:28AM by fastest963.
Re: Those dumb "MYSQL server has gone away errors"
November 08, 2007 12:36AM
I have a quick update...
DON'T USE ABOVE ONE!

it seems that if your ip changes (remote sphider) then mysql denies the request so you need to add...

include "../settings/database.php";

so now the bottom of spiderfuncs.php should look like...

function mysqltest(){
if (mysql_ping() === FALSE){
$numtries = 0;
while (mysql_ping() === FALSE){
$numtries++;
if ($numtries == 5){
$numtries = 0;
include "../settings/rdatabase.php";
print "<font color = 'blue'>&nbsp;Trying to Reconnect!...&nbsp;&nbsp;&nbsp;</font>";
flush();
$numtries++;
} else {
print "<font color = 'red'>Mysql Server Not Avaliable!...&nbsp;&nbsp;</font>";
flush();
}
sleep(20);
}

}

}

also note the &nbsp; those are just for display purposes

MUST DO FOLLOWING!!!
copy /settings/database.php and then rename to rdatabase.php
then edit and change the bottom to

$success = mysql_pconnect ($mysql_host, $mysql_user, $mysql_password);
if (!$success)
print "<b>Cannot connect to database, check if username, password and host are correct.</b>";
flush();
$success = mysql_select_db ($database);
if (!$success) {
print "<b>Cannot choose database, check if database name is correct.</b>";
flush();
}


Now you need to search through spider.php and spiderfuncs.php and find all instances of "mysql_query(" (no quotes).
Before every mysql_query put...

mysqltest();

Now your DONE!



Edited 5 time(s). Last edit at 11/14/2007 12:08AM by fastest963.
Re: Those dumb "MYSQL server has gone away" errors
November 12, 2007 09:43PM
I added this and I still get the error with out "trying to reconnect" Like your script wants...

The include "../settings/database.php"; goes where? Spider.php?
Re: Those dumb "MYSQL server has gone away" errors
November 13, 2007 02:32PM
The problem might be that you didn't make another database.php file.
The /settings/database.php file has a kill command in it. So you must copy the /settings/database.php file and rename the new copied one to rdatabase.php then change the bottom code in rdatabase.php to....


$success = mysql_pconnect ($mysql_host, $mysql_user, $mysql_password);
if (!$success)
print "<b>Cannot connect to database, check if username, password and host are correct.</b>";
flush();
$success = mysql_select_db ($database);
if (!$success) {
print "<b>Cannot choose database, check if database name is correct.</b>";
flush();
}

---- You will leave the top configuration the same just change the bottom starting with $success = -----


I have just bolded something that you might not have done.
If it still doesn't work then post back or PM me.



Edited 1 time(s). Last edit at 11/14/2007 12:11AM by fastest963.
Re: Those dumb "MYSQL server has gone away" errors
November 19, 2007 12:30AM
I started over from scratch this time JUST as you said and I have no problems now! =) So it was something I missed..

However now after my spider hits around site 5700 in the spider The RAM on my server is full! lol but thats more than likely my fault for trying to spider too much! =)

Thanks for your great info!

-Flyntlok

=======
I can make custom IE and Firefox toolbars for SPhider search engine sites! Hit me up if you're interested in one for your site.
=======
Re: Those dumb "MYSQL server has gone away" errors
November 19, 2007 02:32PM
You want your ram to go down, apply this

If you really want to get rid of this five minutes, then use the code below. Having said that, this spreads the five minutes imperceptibly across your spidering time as more database requests have to be made.

Delete this:-

$all_keywords from global at top of index_site().

Then delete this from index_site();

mysqltest();
$result = mysql_query("select keyword_ID, keyword from ".$mysql_table_prefix."keywords"winking smiley;
echo mysql_error();
while($row=mysql_fetch_array($result)) {
$all_keywords[addslashes($row[1])] = $row[0];
}

and replace save_keywords() with code below

code is tested.

function save_keywords($wordarray, $link_id, $domain) {
global $mysql_table_prefix;
reset($wordarray);
//loop through the word array
while ($thisword = each($wordarray)) {
$word = $thisword[1][1];
//$word is already database safe and has been
//cleaned with addslashes() in clean_file();
$weight = $thisword[1][2];
if(strlen($word) >30 ){
continue;
}else{
mysqltest();
$result = mysql_query("SELECT keyword_id from ".$mysql_table_prefix."keywords WHERE keyword='$word'"winking smiley;
echo mysql_error();
$numrows = mysql_num_rows($result);
//if number of rows is nothing then the word is not in keywords
if ($numrows == 0) {
//insert the word
mysqltest();
mysql_query("insert into ".$mysql_table_prefix."keywords (keyword) values ('$word')"winking smiley;
//oops...the word did exist
if (mysql_errno() == 1062) {
//select the keyword id
mysqltest();
$result = mysql_query("select keyword_id from ".$mysql_table_prefix."keywords where keyword='$word'"winking smiley;
echo mysql_error();
$row = mysql_fetch_row($result);
$keyword_id = $row[0];
}else{
//no error so we get the last insert id
$keyword_id = mysql_insert_id();
}
}else{
//the word did exist in keywords
$row = mysql_fetch_row($result);
$keyword_id = $row[0];
}
}
$wordmd5 = md5($word);
//if not yet started the $inserts[$wordmd5] key for the arry
//HOHOHO....cheeky little bit of code coming up
if(!isset($inserts[$wordmd5[0]])){
//you can access the first letter of any string as if
//the string was an array.
//$wordmd5[0] gives the first letter.
//gets rid of the need to call substr();

//start it
$inserts[$wordmd5[0]] = "($link_id,$keyword_id,$weight,$domain)";
}else{
//add to it
$inserts[$wordmd5[0]] .=",($link_id,$keyword_id,$weight,$domain)";
}
}
//loop through $inserts;
for ($i=0;$i<=15; $i++) {
$char = dechex($i);
if(isset($inserts[$char])){
//insert into correct link_keyword table
$query = "insert into ".$mysql_table_prefix."link_keyword$char (link_id, keyword_id, weight, domain) values $inserts[$char]";
mysqltest();
mysql_query($query);
echo mysql_error();
}
}
}

hope this helps


Thanks to gandalf for the code
and i think i put in all of the mysqltest(); however, in this text box on the forum its kind of hard to see.
Re: Those dumb "MYSQL server has gone away" errors
February 03, 2008 03:23AM
You can also with php5 put an @ infront of mysql_query()

@mysql_query("...

it will simply not show the error !
Re: Those dumb "MYSQL server has gone away" errors
May 18, 2008 01:55AM
I tried this and this is so great... But, there is a huge error. After I put all codes and when I indexing Sphider is not indexing but it is continuing site to site. What is the reason?

This MySQL server has gone away error is SICK... Help me and all other who have SICK.

Thanks,
Prasad
Re: Those dumb "MYSQL server has gone away" errors
June 09, 2008 05:23PM
Can you explain what you mean? By site-site.
Re: Those dumb "MYSQL server has gone away" errors
June 21, 2008 07:44PM
fastest963 Wrote:
-------------------------------------------------------
> Can you explain what you mean? By site-site.


When I spider. Sphider is running but it is not indexing.
Re: Those dumb "MYSQL server has gone away" errors
July 07, 2008 01:14AM
Help-me!!!!

"MYSQL server has gone away"

I tried all MOD's...
Re: Those dumb "MYSQL server has gone away" errors
July 11, 2008 03:38PM
I would suggest starting the MySQL Slow Query log to see what MySQL may be stalling on. My guess is that a number of queries are taking a long time to process causing the connection to die / timeout.

This article should get you guys in the right direction:
[www.databasejournal.com]

[dev.mysql.com]

-Bing
-------
Turn your Sphider into an Ads for Search and Ads for Content Advertising Network Free!
[www.inclick.net]
Re: Those dumb "MYSQL server has gone away" errors
July 29, 2008 12:35AM
I've tried following the mods posted by fastest963 on November 13, 2007 (2:32pm, posted above). According to my web host, they disabled the MySQL "flush" command, so I changed the code to "reset".

Seems to be working so far -- only tested on small sites, but it's working.



Edited 1 time(s). Last edit at 07/29/2008 01:09AM by Dekortage.
Re: Those dumb "MYSQL server has gone away" errors
March 15, 2012 05:03PM
I tried following these instructions. I keep getting this error on a localhost server. However, the instructions are very hard for me to follow due to the bad grammar. Does anyone have any idea how to fix this?
Sorry, only registered users may post in this forum.

Click here to login