NYCPHP Meetup

NYPHP.org

RegEx vs. SAX

Mark Armendariz nyphp at enobrev.com
Fri Mar 21 17:28:44 EST 2003


Hello all,
 
I have a php based socket / xml chat server that I'm using to serve a
flash based frontend using flash's xml_sockets.  All the major goods are
done, and working well.  My dilemma is the xml parsing on the server
side.  Basically, all messages and commands are sent to the server in
xml form.  So a new message looks like:
 
<message member_id="1" room_id="44">The message Text</message>
 
or keypress:
 
<key member_id="1" room_id="44" on ="1" />
 
<key member_id="1" room_id="44" on ="0" />
 
You get the idea.
 
Anyways, currently, I have each command that comes into the server
running through a switch, which does a preg_match like this:
 
switch( true ) {
                        case preg_match('/<message member _id="(.*)"
room_id="(.*)">(.*)<\\/message>/', $message, $attributes) :
                                                
                                    $this->message( $client_id,
$attributes[1], $attributes[2], $attributes[3] );
                                    break;
                                                            
                        case preg_match('/<key member _id="(.*)"
room_id="(.*)" on="(.*)" \\/>/', $message, $attributes) :
                                                            
                                    $this->key_pressed( $client_id,
$attributes[1], $attributes[2], $attributes[3] );
                                    break;
            }
 
These run the correct functions which do any database stuff required and
then broadcasts the message, etc to the correct clients.
 
Now, my question is, would it be less resource intensive to use php's
inherent xml functions to parse the incoming commands or should regex be
the faster of the two.  I don't mind doing speed tests and such to find
out, but before I jump into the testing, I had hoped someone here might
have an idea.
 
Thanks!!!
 
Mark Armendariz
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030321/714dbdef/attachment.html>


More information about the talk mailing list