Persistent PHP socket server

I'm planning the development of a server written in PHP that can service socket requests. I use a free host (Heliohost) for testing, and it has cPanel. So far the only thing I've been able to think of to have a PHP script always running is to write a cron job that runs a bash script to check ps to see if the PHP is already running, and if it isn't, start it.

Is there a better way? Perhaps a way for a PHP thread to be started on an HTTP request and continue to run in Apache after the request has been serviced?


You will almost certainly not have success running persistent processes from Apache. It is designed to prevent that scenario (though if you can get to the fork(2) system call, it is probably do-able). I wouldn't recommend trying it though.

What would make more sense is if you use a hosting provider that gives you the ability to write your own crontab(5) specifications and run the PHP interpreter directly. Then you could just add a line to your crontab(5) like:

@reboot /path/to/php /path/to/script.php

Your script should probably perform the usual daemonization tasks so that cron(8) isn't stuck waiting for your process to exit.

Need Your Help

Itemrenderer in Datagrid wrong display

flash flex actionscript itemrenderer

I have a datagrid with an itemrenderer component.

Running a web-spider on Java

java windows web web-crawler heritrix

Launch web spider on Windovs 8.1 64-bit. Tried not to connect additional libraries, and eventually climbs mistake.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.