PHP Multitasking? (aka "PHP MSN AI Bot")
Posted: Mon Jul 28, 2003 6:52 pm
Okay, I've written basically a full web-based msn bot in php, and it's working perfectly so far. I can connect to the server, get my contact list, show their statuses, log out, talk to people..
BUT in my quest to create the world's first fully web-based msn client, I've hit a huge pitfall. PHP can NOT multitask.
Here's the problem. If you've studied the msn protocol you'll see that in a switchboard session (conversation), the user first connects to the specified switchboard session (I'm using a separate php file - conversation.php) and then starts receiving packets, mainly about the user in the conversation, stuff like that. After the header stuff is done with, you start receiving far less data: all you get is "User is typing", "User sent this message: foobar", and "User has left conversation". My problem?
That's the loop that runs after the headers have been dealt with, for retreiving those 3 common types of messages (typing, sent message, left room).
I couldn't get a textbox to submit to the running php script, so I was going to submit every message from the textbox into a mysql database, and then the "conversation" php file, in that while() loop, would check for new messages every 2 or 3 seconds. Sounds moderately easy at first, but it turns out it's impossible. The while() loop is *only* executed when I get new data from the socket.
The more clever amongst you may have seen 'ticks', a so-called novel approach to PHP multitasking, using code like this:
That will run foo() (or check_database, in my case) every few ticks, no matter what else is happening, right? Wrong. All that ticks crap in that example is redundant, it's the same as saying "foo();" once. That's not multitasking at all, it's.. useless.
I'm not sure if anybody is still reading this, and if so, I'm not sure you understand my problem, but if you do, AND you have ANYTHING at all to say (hint, idea, sympathy) PLEASE say it, I've put too much time into this thing to be screwed over at this point.
By the way, the working bot is online at http://www.qartis.com/bawt/contactlist.php , and his msn handle is "qartisbottery@hotmail.com".
BUT in my quest to create the world's first fully web-based msn client, I've hit a huge pitfall. PHP can NOT multitask.
Here's the problem. If you've studied the msn protocol you'll see that in a switchboard session (conversation), the user first connects to the specified switchboard session (I'm using a separate php file - conversation.php) and then starts receiving packets, mainly about the user in the conversation, stuff like that. After the header stuff is done with, you start receiving far less data: all you get is "User is typing", "User sent this message: foobar", and "User has left conversation". My problem?
Code: Select all
while (!feof($fp)){
//get data from $fp
//extract their message and parse the data
}I couldn't get a textbox to submit to the running php script, so I was going to submit every message from the textbox into a mysql database, and then the "conversation" php file, in that while() loop, would check for new messages every 2 or 3 seconds. Sounds moderately easy at first, but it turns out it's impossible. The while() loop is *only* executed when I get new data from the socket.
The more clever amongst you may have seen 'ticks', a so-called novel approach to PHP multitasking, using code like this:
Code: Select all
<?
function foo(){
echo "bar";
}
register_tick_function("foo");
declare (ticks=1) 1;
?>I'm not sure if anybody is still reading this, and if so, I'm not sure you understand my problem, but if you do, AND you have ANYTHING at all to say (hint, idea, sympathy) PLEASE say it, I've put too much time into this thing to be screwed over at this point.
By the way, the working bot is online at http://www.qartis.com/bawt/contactlist.php , and his msn handle is "qartisbottery@hotmail.com".