WildPHP / irc-bot

A simple and modular PHP IRC bot
MIT License
84 stars 24 forks source link

Use streams instead of just sockets through fsockopen. #32

Closed GuntherDW closed 9 years ago

GuntherDW commented 9 years ago

In the current codebase there is no method to check if there actually was a change in the socket. Combined with the while(true) loop this creates a lot of wasted CPU cycles.

In PHP5 you can create a stream which acts more or less the same as fsockopen, but has the added bonusses of using socket_* calls. This includes stream_select(), which allows you to wait for events in the socket stream with optional timeout. It will effectively just wait until either it receives a message from the IRC server, or the timout occurs. Whichever comes first.

In my pull request I have a default timeout of 1, which in effect is "1 second." (On Linux at least) This makes it so that other hooks like the reminders will still run relatively smooth, while still remaining to be responsive towards IRC.

This change will also quite easily just work in the modular rewrite branch. I haven't extensively tested this code just yet though, so there might still be some issues that I haven't found.

NanoSector commented 9 years ago

Thank you for your pull request! However, we have since moved work on the bot to the modularity rewrite branch. We should probably make this more clear on the readme for master.

GuntherDW commented 9 years ago

I noticed, but I wasn't sure if it was a new "definitive" version so to speak. The changes however translate over just as well, seeing as it is quite a small change, but I'll create a new PR on the modular branch then.