yes what you need to do is everytime the server sends a ping message you must send back a pong message indicating you are alive, if no pong message is sent it will close your connection, the message you will recieve will look like this ussually
PONG :irc.server.com
then you ussually send back a message liek:
PONG :irc.server.com
use fgets() in a loop to recieve the server messages then explode them and use a couple if's and PONG the server when you get a PING, you'll stay on longer that way, a little irc bot i have written has been connected for 3 days now with no problems all thanks to my tasty PING PONG loop