Re: Possible?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, April 28, 2006 6:13 pm, René Fournier wrote:
> Simple problem: Many client apps need to send data to a server.
>
> By default each client will open a persistent TCP socket connection
> to a common IP address:port (10.10.10.10:1234) and write to it (which
> the server will save/log, etc.).
>
> My question is, what should be ready to listen at the IP:port? I was
> thinking of writing a PHP command-line socket server that listens at
> that port. But there will be a potentially huge number of clients
> connecting simultaneously (1000s), not transmitting a lot of data per
> se, but a lot of connections...

Bring it on.

[bunny]
The PHP script you write just has to NOT QUIT, but keep on going and
going and going and...
[/bunny]

> Anyway, instead I thought writing a
> simple PHP script?say, listener.php?that gets executed by the web
> server and enters a socket_read loop until the client terminates the
> connection (set_time_limit(0)).

Don't tie up your HTTP connections for this.

> Does this sound like a good way to do it? This way, Apache handles
> all the connections, and PHP is instantiated each time, but without
> having to fork processes, etc, and without having to do PHP CLI.

You're making life WAY too complicated for yourself!

> Anyway, I've started looking at this, but I'm not quite sure if it's
> even possible. I mean, can "something" send a request to Apache, and
> continue to write data along that TCP socket? Normally, HTTP requests
> include GET or POST for such data, but this is not a a web browser
> that's opening the connection.

You probably can't do this, and even if you could, you don't WANT to
do this!

> Hope I'm somewhat clear. Just struggling through some options
> here.... Anyway, thanks in advance for any suggestions.

You should try the simple solution first:

http://php.net/sockets

The "talkback" server example there is a good starter kit.

You then just need to have it be able to handle the connections and
put the data somewhere -- A MySQL ISAM table is probably the easiest
and most likely to handle the volume you want, at a guess...

If THAT is not fast enough, then your next move is not to try and hack
Apache to get a "pool" going, but to find something LIKE the Apache
dispatcher to wrap around your server.

Or, possibly, consider setting up a "pool" of hardware to handle the
connections.

But first, make sure that the straightforward approach is "too slow"
before you get yourself all bent out of shape trying to solve a
problem that doesn't exist. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux