 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Simas Toleikis' Blog: Writing a PHP daemon application
by Chris Cornutt January 19, 2011 @ 11:51:34
Simas Toleikis has a new post today looking at a method he's found for creating a simple daemon application in PHP. He gives you the basic outline of how it works (with a bit of code included) but not a specific example.
There is a special group of applications that require a different PHP script execution model. [...] All of [these special] applications need to be run in the background as daemons - something that PHP was never designed/supposed to be good at. The plain C language is a weapon of choice when it comes to writing a daemon implementation, but then again, if the application in question does not depend on high performance and concurrency - PHP can do the job quite well.
He talks about using the command line interface to run the scripts, creating the while loop to keep execution going and creating the non-blocking socket so that the script can accept new client connections. He also mentions using upstart to run the script in the background and the proctitle PECL extension to give the process a custom name in the process list. He also touches on log files and forking/parallel processing.
voice your opinion now!
daemon application tutorial proctitle cli upstart
Re-Cycled Air Blog: PHP Dark Arts Daemonizing a Process
by Chris Cornutt October 29, 2010 @ 11:02:36
On the Re-Cycled Air blog Jack Slingerland has posted another in his "Dark Arts" series looking at some of the lesser used PHP features. This time he focuses in on daemonizing a process by forking it off into the background.
One of the many things you don't often do with PHP (actually, I'm not sure you do this much with any language) is daemonize a process. A daemon is program that runs in the background (read more here). On Unix systems, processes are usually created by forking the init process and then manipulating the process to your liking. To create a daemon though, you need to get the init process to adopt your process. To do that, as soon as you fork the parent process, you kill the parent. Since you child process is parent-less, the init process generally adopts it. Once that happens, your process has been daemonized.
He uses the pcntl_fork function to spawn off the child process, detach it from a terminal window, create a ".pid" file so the system knows about it and then, of course, have the child script do something.
voice your opinion now!
daemon process child parent tutorial
Kevin Schroeder's Blog: You want to do WHAT with PHP? Chapter 8
by Chris Cornutt September 24, 2010 @ 12:39:17
On his blog today Kevin Schroeder has the latest in a series of excerpts from his book "You Want to Do WHAT with PHP?" - a section of the chapter on daemons.
PHP is a language generally not suited for running daemons. That said, PHP can do it, and in certain circumstances does it sufficiently for the job. In this chapter we look at some of the things you need to know about to build a PHP-based daemon. This excerpt doesn't feature any code, but it does set the foundation for why I think PHP is fine for daemons in some circumstances.
The excerpt is mainly the first part of the chapter that just introduces the idea of daemons including some of the right and wrong uses, using the right tool for the job and how using PHP for a daemon can help with needs in a place where PHP might already be a norm.
voice your opinion now!
book excerpt kevinschroeder chapter daemon
Mark Karpeles' Blog: PHP DNS Daemon
by Chris Cornutt February 17, 2009 @ 12:06:24
Mark Karpeles has created something that most people would think he's crazy for - a DNS daemon written in PHP:
If you want to tell me I'm crazy, you can post it in a comment here, it makes me happy. I had some reasons to dislike bind9 which finally made me write my own DNS daemon, and I'll explain that here. My need was to have a stable dynamic DNS server working in most environments, with an easy to configure master/slave relationship (with realtime synchronization), and a way to change records instantly from PHP...
Rather than using the (slightly unstable) dlz technology to pull the information from a MySQL database, he opted to roll his own that includes support for:
- RFC 1035 standards
- realtime data update
- slave/master relationship (with a keepalive connection)
Want to try it out for yourself? Drop him a line and ask about it!
He's also run some statistics on the performance of the daemon as compared to the standard BIND installation and come up with some instructions on how you can install and configure your own instance.
voice your opinion now!
dns daemon mysql custom rfc1035 master slave synchronize
Mark Karpeles' Blog: proctitle a new step for pinetd
by Chris Cornutt January 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.
voice your opinion now!
pinetd proctitle extension daemon tcp udp name process fork
Kevin van Zonneveld's Blog: Create daemons in PHP
by Chris Cornutt January 12, 2009 @ 08:47:31
In a new post to his blog Kevin van Zonneveld talks about making daemons, backend scripts that run independent of a web server.
Everyone knows PHP can be used to create websites. But it can also be used to create desktop applications and commandline tools. And now with a class called System_Daemon, you can even create daemons using nothing but PHP. And did I mention it was easy?
He starts with a definition ("a linux program that runs in the background") and why PHP makes a good language choice for creating them. His example uses the System_Daemon PEAR class to do most of the heavy lifting. To use it, you only need to include it at the top of the script and make two calls to the setOption and start methods to have the rest of the code all set to run as a daemon.
The example code sets up a daemon complete with support for command-line arguments and the ability to be run from init.d on the local system.
voice your opinion now!
tutorial daemon shell script systemdaemon pear package
DevShed: Managing Standalone Scripts in PHP
by Chris Cornutt September 07, 2006 @ 16:19:52
DevShed continues their look at standalone PHP scripts (server-side scripting, not on the web) in part two, "Managing Standalone Scripts in PHP" excerpted from the book "Advanced PHP Programming" from George Schlossnagle.
Last week, we began our discussion of PHP standalone scripts. This week, we'll be talking about child processes, shared resources, signals, and writing daemons.
They jump right in, going first for a look at forking off child processes from the script using the pcntl functionality you'll need to build into PHP. Resource management is key to working with server scripts, and they show you how to close them out when you're through. Next up is a brief look at the types of signals that you can send to the child processes, and some good rules to follow for writing daemons in PHP.
voice your opinion now!
standalone script serverside daemon signal resources standalone script serverside daemon signal resources
|
Community Events
Don't see your event here? Let us know!
|