UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2007-07-19 08:49 AM

WWJD
Member
Registered: 2007-07-19
Posts: 2

Re: Socket Server PHP Daemon overflowing...

Hello guys!
I've got this problem. I've got a PHP daemon running on my FreeBSD server.
The daemon is the following script:

ob_implicit_flush(true);
$system_root_path = "/data/home/htdocs/";

require_once($system_root_path . "common.php");

set_time_limit(0);
$bind_host='192.168.0.19';
$port = 1460;

// create instance of GameServer class
$daemon = new GameServer($casino, $bind_host, $port);

while(true) {

        // process queries
        $daemon->process();
        
        // no clients - sleep 20msec
        if((int) count($daemon->_data["s_clients"]) == 0) {
                usleep(20);
        }
}

GameServer class extends SocketServer class that handles sockets.
This daemon is a background process that interacts with a Flash game through sockets.
The problem is - it's constantly increasing in size.

Here is the process table:
  PID USERNAME  THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMAND
65460 www         1  96    0 24512K 15788K select   0:07  0.98% httpd
65409 www         1  96    0 24540K 15780K select   0:11  0.00% httpd
66818 www         1  96    0 21960K 13284K select   0:10  0.00% php

So it's SIZE and RES values go up every time I press the play button in the Flash game.

Anybody has an idea what the problem lies in?

Offline

#2 2007-07-19 01:36 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Socket Server PHP Daemon overflowing...

I know absolutely nothing about PHP, but my guess is that you're leaking some kind
of resources somewhere...  Does this process() function close the sockets when it's
done with them?  I suspect that memory management in PHP is rather implicit, so
there's no explicit freeing of memory required?  If so, then maybe the growth you're
seeing is normal and expected, and eventually some garbage collector will kick in
and take care of things, or something... *shrug*

Offline

#3 2007-07-20 03:56 AM

WWJD
Member
Registered: 2007-07-19
Posts: 2

Re: Socket Server PHP Daemon overflowing...

Offline

#4 2008-08-14 12:52 PM

swan
Member
Registered: 2008-08-14
Posts: 2

Re: Socket Server PHP Daemon overflowing...

Offline

#5 2008-09-11 02:00 PM

vic
Administrator
Registered: 2002-04-16
Posts: 90
Website

Re: Socket Server PHP Daemon overflowing...

Offline

#6 2008-09-14 06:28 AM

swan
Member
Registered: 2008-08-14
Posts: 2

Re: Socket Server PHP Daemon overflowing...

im guessing all this but, phpembed looks good if you somehow know c++ and php _and_ decide for some reason you want to dev in c++ and use php type eval or func access. i could see phpembed being used for a few things, but why one would want to dev a daemon in c++ and then use phpembed for functions only (eval maybe but also what for really), when those functions are just wrappers for either c, c++ libraries on the system anyway (unless they are all compiled statically into php) and your living on an embedded system or summat.

i havent used php-cgi in a while (run from command line, not php-cli however), but i think you can call php-cgi with runtime args and have the HTTP environment loaded automagically for you - point is you need the client HTTP input preparsed and envrionment setup before you get into the user code space execution - and yeh, if you STDIN to php-cgi i think chances are high that it will also setup the HTTP envrionment automagically. so the STDIN(php-cgi)/xinetd combo is infamous, but also i guess the whole idea of dropping to shell (xinetd->stdout->stdin->exec) still freaks everyone out.

php-cli probably wont have any flags to preparse and setup a HTTP envrionment for the coder before their userspace program is executed (via runtime args, or with preparse switch on STDIN. yeh im sure it still has php-sapi, but no-HTTP-thing is using it before your code is loaded. so unfortunately there is no actual HTTP buffer persay being manipulated, or written out to its own ob_buffer type space. eg. calling header() will be pretty useless.

phplib/apache would also have its own beefcake of a handler over xinet, preloading, caching, etc, etc. and apache is a beefcake of a daemon period. its also extermely useful and generic - but if you just want to beekcake your php script _only_ and not have a beefcake of a daemon _and_ (mainly if) you are a php coder already, then sonic is worth a look, their might be other generic daemons for php out there but the following is all i know of (apart from 101 howtos for php and daemonisation), nanoserv is php library (more work, eg. heavily use the API plus load it on the arch yourself), nanoweb is a stdin->php-cgi/xinet combo solution (less work but HTTP related only). sonic is a php daemon (more work, but hopefully also inheritly more features bang for buck).


imho, if you can dev in c,c++, do it, usually rip or jump off from generic server daemon code base and do the nasty inside the while loop and viola - done. if anyone wants to do the same in php they can obviously, sonic is just another generic server daemon base to jump from - is all. but even for those who can code c,etc, maybe they are tired of manipulating a truely middle level higher language just to script shit (dev time at the very least) eg. i really dont want to have to setup any arch/memory space management anymore. plus all the other pros (and yes cons). but also mainly because i think php has always got it right all round when it comes to bang for buck.

Offline

Board footer

Powered by FluxBB