"MySQL server has gone away" with CodeIgniter and MySQL.

2,469 views
Skip to first unread message

s0l1dsnak3123

unread,
Apr 4, 2010, 6:40:53 PM4/4/10
to Phirehose Users
Hi there guys,

I've developed an application using the codeigniter framework which
consumes tweets that are relevant to my search and puts them in a
database. The script works, but times out regularly, complaining that
"MySQL server has gone away". Under normal circumstances, I'd use
mysql_ping($conn) to remedy this and keep the connection alive.
However, the library does not use codeigniter. How would I ping the
mySQL connection codeigniter set up, and also where within the library
would I ping?

Thanks in advance,
John.

Ps: a copy of how the library is being used can be found here:
http://stikked.com/view/6959135

Fenn

unread,
Apr 4, 2010, 9:05:39 PM4/4/10
to Phirehose Users
Hey John,

I'm not familiar with codeigniter itself, but I have ran across that
error message before a few times. There are a few causes, most of
which are discussed here:

http://blog.taragana.com/index.php/archive/mysql-tip-mysql-server-has-gone-away-or-lost-connection-to-server-during-query-fix/

If your stream is very quiet (ie: tweets only very occasionally) it
could be timing the MySQL connection out. You could always send an
arbitrary query to the server every 10 minutes or something (ie:
"SELECT CURRENT_TIMESTAMP()") just as a keep-alive.

Probably the easiest way to do this is put some code into
checkFilterPredicates() (which is called every 5 seconds) that checks
if you've done an "SQL PING" in the last 10 minutes. If you haven't,
do the ping, then reset the timer.

Good luck!

Cheers,

Fenn.

s0l1dsnak3123

unread,
Apr 5, 2010, 6:10:12 PM4/5/10
to phireho...@googlegroups.com
Thanks alot Fenn, that was very informative. For future reference's sake, in codeigniter, if you want to send a ping, you use the function $this->db->reconnect();. Here is my implementation of what you said for anyone else who might happen to come across the same problem with codeigniter: http://stikked.com/view/97695038

Again, thanks alot for a very clear and informative answer,
John.



--
To unsubscribe, reply using "remove me" as the subject.

Reply all
Reply to author
Forward
0 new messages