Hi there.

I'm presently coding a chat application in php / mysql. The server I'm on has zend optimizer which is supposed to make scripts a little faster. Though I'm considering moving to a vps and installing apc or xcache.

I'm somewhat new to coding though in php and was wondering. When is a script considered big / cumbersome for execution?

Eventually, my plan would be for my site to have between 100 to 250 concurrent users at a time. This doesn't always necessarily translate to 100-250 requests per second, however, it could if they were completely active.

My chat script I set up in this way.

Login.php (html page, displays login form, directs to validate.php)

Validate.php (holds pages worth of security checks, functions, etc, before authorizing the person to continue on and build a valid session ID in the mysql database - I require all users to register to use the site)

Once logged in, the user will be at "chat.php" which builds all the variables, checks for proper session ID every "pull" of the chat, or manual refresh basically. It also checks for /commands and requires command.php (which each individual command checks sessions as well to prevent malicious executions)

Overall. My chat.php script is about 6 to 7 Kilobytes (KšŸ˜Ž in size. About 200 lines of code. possibly up to 300 lines of code at the utmost, depending on the size of the /command file required if a /command is input.

on each execution of the script there are anywhere between 2 database queries minimum (displaying chat room text from one table, and checking session id from another) to a maximum of 6 database queries per run.

My script is very simple and basically just runs from top to bottom passing through a bunch of "if" statements to match up to things that could possibly happen.

based on the above, how many users do you think this sort of script could concurrently support. both just normal php and perhaps using XCACHE or another form of php cache enhancer?

I'm not super fond of iframes or javascript to push the data "live"

the chat room text consists of 20 lines displayed (20 most recent posts) and holds a total of the most recent 50 lines. So this means at the most the chat script has to go through is 50 rows of data to display chat room text wise. the user database is Nil as all the processing for it is done in validate.php and that file is only required once during login and builds the users information into variables which are cached.

how many users could I expect to support realistically at the same time all actively "chatting" with my current architecture.

how could I make it better short of something drastic like trying to figure out heap tables or innodb stuff (way beyond my scale at the moment though I've read up on them)

    i doubt php is really the language for this kind of app, i would think java would be a much better idea, you can then push a lot of the processing on to the clients machine.

      I need it to be as simple as possible. Java is mostly out of the question for what I want to provide. which is a somewhat busy, web based chat people at work late at night or at school can hop on without fear of any java incompatibilities etc. If I have to cap a servers maximum users load and open more servers if it were to ever get that busy that's probably the route I'd go, over doing java.

      The one thing I did find was a frame based solution I might be willing to do although I'm not sure how much this cuts down overhead wise but check out

      www.alamak.com

      login with frames enabled checked. I realize it is coded in perl, most likely mod or fastcgi but the principle could be the same. single stable frame at the bottom for posting while the top frame meta refreshes every few seconds or so.

        just wanted to post an update... found a solution to my problems for speed.

        i'll keep my design the way i have it as a simple php program with mysql.

        what i have changed is my web host. i went from regular vps to a vps at wiredtree.com

        i went with the setup on a quad core computer, with litespeed web server (instead of apache) and XCACHE installed.

        doing a simulated test on my old vps, sending appx 175 connections per second (from a friends private dedicated server) caused my old vps resources to jump even on a simple script like this. cpu usage went from 0 to 50-60 CPU's in a matter of 20 seconds and page reloads were slower (1.5-2 seconds) with that many requests coming in.

        Happy to report on the new server, with the new litespeed server and XCACHE (probably more thanks to xcache than anything else) i'm sending 300 connections per second to my script with authentic login info (meaning its submitting proper GET info which actually lets the php script process and return output results) and my CPU's aren't even going over 10, my ram is well under 40 MB of useage and it's not even causing the new one to flinch. So I should be able to easily host 150-200 concurrent users or more on this setup.

        I highly recommend XCACHE to anyone using PHP that wishes to see immediate 300-600% speed gains as it caches the script into memory.

        also to speed things up i moved my room files (chat text data for each chat room) into HEAP tables instead of TEXT files to avoid the bottleneck that is my servers hard disk. This also probably played a major factor in the performance increases as well.

        Cheers.

          Write a Reply...