Question

First of all, hello, and thanks for reading in advance.

In the past few days I've been working on writing a useful bot for a SAMP server to use. As such, they use IRC (Internet relay chat) bots to display in-game information, such as things said in chat, actions done by players and so forth. So far so good, got PHP knowledge down here and there, however there is one problem which I haven't been able to fix. After some time (somewhere between 20 and 40 minutes), the script simply stops, and it no longer replies to PING requests from the server, and therefore the IRC server disconnects the client. It took me some time to get an idea as to what is causing this to happen, and it might be that the command prompt itself has reached some sort of line or character limit, as it sometimes stops echo-ing information right in the middle of a line. (Something like: IRCBot PRIVMSG #channel Player: look guys I just fou ) Is there a way to prevent this from happening? So far I've put this at the beginning of my script:

set_time_limit(0);
ini_set('display_errors', '1');
ini_set('max_execution_time', '0');

Fun fact, none of those worked. If it helps, my script's way of echo-ing goes like this:

while ($data = fgetss($sock)) {
echo nl2br($data);
flush();
// Script below

Any sort of help is appreciated. Thanks for reading.

Was it helpful?

Solution

I made a mistake with using fgetss instead of fgets. The problem was that fgetss stops at EOF (end of file), which caused my issue.

For future reference to anyone who might read this thread with a similar issue, make sure you use fgets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top