Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso:
Building TCP server daemond with PHP and Rachet
Apr 13, 2015 @ 10:18:41

Gonzalo Ayuso has a new post to his site today showing how to create a TCP server daemon with PHP with help from the Ratchet toolset. Ratchet is a library that makes it easier to work with WebSockets directly from PHP.

In my daily work I normally play a lot with TCP servers, clients and things like that. I like to use Linux’s xinet.d daemon to handle the TCP ports. I’ve also written something about it. This approach works fine. The problem appears when we call intensively our xinet.d server. It creates one PHP instance per request. It isn’t a problem with one request in, for example, 3 seconds, but if we need to handle 10 requests per second our server load will grow. The solution: a dedicated server.

In a setup similar to how Silex registers callbacks, he's created a PHP-based server that listens on whatever ports are defined for incoming connections and processes the data accordingly. He includes several code samples that show it in use, both in simple request handling and more complex configurations based off of a YAML file definition. He ends the post with a method he uses to "emulate" threading in his processing with the help of a Silex app and HTTP requests to hand off the processed and remove the blocking problem PHP introduces.

tagged: tcp server daemon ratchet websocket silex tutorial

Link: http://gonzalo123.com/2015/04/13/building-tcp-server-daemon-with-php-and-rachet/

Mark Karpeles' Blog:
proctitle: a new step for pinetd
Jan 22, 2009 @ 11:12:17

If you've ever worked with forking processes in PHP, you know things can get a little difficult when you have more than one process going at a time. Identification can become a hassle, especially if you need to kill one off because of performance issues. If you've found yourself in this spot before, you might want to check out this update Mark Karpeles has made to his pinetd project to allow for naming of those forked processes.

Ever wanted to give meaningful names to your processes when you pcntl_fork() with PHP ? proctitle is the extension you’re looking for! Adapted from bug report #29479 and code initially wrote by Midom for Wikipedia, the proctitle extension allows for a process to change its own displayed title in the system’s process list.

The extension (seen in action here) is an interface for making different sorts of daemons, including the ability to give them names. You can check out the project here.

tagged: pinetd proctitle extension daemon tcp udp name process fork

Link:

Lukas Smith's Blog:
Persistent connections with MSSQL
Dec 11, 2008 @ 12:01:26

Lukas Smith is looking for a little help on a strange problem he's seeing connecting to a SQL Server with persistent connections:

We are connecting to SQL Server via mssql_pconnect(). MaxChilds is set to 256 and we are only establishing one connection per request. So as a result I am expecting a maximum of 256 established connections. A client went into production yesterday and due to a missing index the server ended up being insanely loaded, as the queries started to block each other. The sysadmin checked the state of things via netstat and found that there were close to 500 tcp connections to the SQL Server. What gives?

He checked FreeTDS and the MaxRequestsPerChild settings to ensure that nothing there could have caused the problem, but hasn't found any hints so far. If he can't solve it right away, he also wonders if there's a way to kill idle connections if they're not used in a certain amount of time.

There's already one connect that mentions a similar issue but with Oracle connections, also on RHEL, but no definitive answers so far.

tagged: persistent connection mssql mssqlpconnect tcp problem freetds

Link:

DevShed:
Developing an Extensible TCP Server with Sockets in PHP
May 30, 2006 @ 17:58:33

Devshed has posted part two in their series of "handling sockets in PHP", this time, with a focus on the creation of a TCP server.

Are you interested in learning how to manipulate low-level sockets in PHP? Your search has finished. This is the second part of the series “Handling sockets in PHP,” and hopefully you’ll find in it valuable material regarding the creation and manipulation of sockets with PHP, in conjunction with numerous illustrative hands-on examples that will help you build socket servers in a few easy steps.

The tutorial walks you through the simple process, looking back at the simple version they made before, looking forward at expaning it to handle multiple client requests, and creating a "socket server" class to automatically handle the creation of the socket.

tagged: sockets tutorial tcp server extensible part2 sockets tutorial tcp server extensible part2

Link:

DevShed:
Developing an Extensible TCP Server with Sockets in PHP
May 30, 2006 @ 17:58:33

Devshed has posted part two in their series of "handling sockets in PHP", this time, with a focus on the creation of a TCP server.

Are you interested in learning how to manipulate low-level sockets in PHP? Your search has finished. This is the second part of the series “Handling sockets in PHP,” and hopefully you’ll find in it valuable material regarding the creation and manipulation of sockets with PHP, in conjunction with numerous illustrative hands-on examples that will help you build socket servers in a few easy steps.

The tutorial walks you through the simple process, looking back at the simple version they made before, looking forward at expaning it to handle multiple client requests, and creating a "socket server" class to automatically handle the creation of the socket.

tagged: sockets tutorial tcp server extensible part2 sockets tutorial tcp server extensible part2

Link: