 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
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
AskAboutPHP.com: CodeIgniter Extending the native 'Model' and make it your own.
by Chris Cornutt November 12, 2008 @ 09:31:24
The AskAboutPHP.com blog has posted a helpful new tutorial for those using CodeIgniter out there - how to extend the native Model class to bend it to your will.
I'm in the process of creating models for my CI project, and realized that certain functions within the models were getting repetitive. Using CI's ability to create my own custom libraries, I was able to create my own custom 'Model' which extends from the core 'Model' object. How this simple architecture has cleaned up my code is simply remarkable.
Rather than overwriting the main Model.php file with some of your own changes, he suggests creating a new library, a "parent model" that can be extended instead to provide some common functions that all of your application's models might need. For something a bit more complex, he also points to this library that extends the models to give it CakePHP-like functionality.
voice your opinion now!
codeigniter framework model extend custom parent library
Jani Hartikainen's Blog: Understanding Doctrine's NestedSet feature
by Chris Cornutt September 02, 2008 @ 10:29:56
On his CodeUtopia blog Jani Hartikainen gives an inside look at a feature of Doctrine, nested sets.
The Doctrine library comes with a feature called nested set, which makes saving trees in a database easy. However, it's quite easy to accidentally cause a lot of extra unneeded queries if not being careful. Here are some pointers to keep in mind while working with the nested set, and some example queries to make understanding it easier.
He gives an example, showing how to get rows from the database - parent and child - and some optimization tips to keep things light. There's also some pros and cons included for doing it either way (the standard fetching or using the more optimized versions).
voice your opinion now!
doctrine nestedset feature fetch database row parent child
Mike Lively's Blog: Late Static Binding (LSB) forward_static_call()
by Chris Cornutt April 09, 2008 @ 11:24:19
On his blog, Mike Lively has posted a look at some of the work he's been doing on patches for the late static binding functionality to be included in PHP, including an example of the updates in action.
This weekend I wrapped up a few small tests and sent the patch in and it was subsequently pushed to php 5.3 and php 6.0. Now, this is not at all the way I wanted things to work, in all honesty I think the patch is pretty hokey but unfortunately nobody really spoke up in support of the changes I wanted to make to parent:: in regards to LSB.
His example shows how to override a static method and push that new method's execution to the parent class (in two ways - safe using forward_static_call and the not so safe calling itself with a parent:: override).
voice your opinion now!
latestaticbinding php5 php6 patch safe unsafe parent forwardstaticcall
Arnold Daniels' Blog: A dark corner of PHP class casting
by Chris Cornutt February 20, 2008 @ 12:08:00
In this blog entry Arnold Daniels talks about an issue he had in the past (needing a bit more functionality than the PEAR DB library could offer) and how he ended up solving it with what he calls a "dark corner" of PHP - class casting.
PHP has a function serialize, which can create a hash from any type of variable, scalars, array, but objects as well. Using the unserialize function, PHP can recreate the variable from the serialized hashed. If we look at how an object is serialized, we see only the properties and the class name are stored.
His method allows for class manipulation via changes to the serialized class information (like changing the value of the name parameter). His "casttoclass()" function makes changing this value simple.
voice your opinion now!
class casting serialize extend parent child
Paul Jones' Blog: Memory Leaks With Objects in PHP 5
by Chris Cornutt September 28, 2007 @ 08:46:00
Paul Jones presents a problem he was having in a new post to his blog - the issue was with memory leaks in objects in a PHP5 application he was working on.
One of the nice things about using a scripting language is that it automates garbage collection for you. You don't have to worry about releasing memory when you're done with your variables. [...] But there is at least one circumstance in which PHP will not free memory for you when you call unset(). Cf. http://bugs.php.net/bug.php?id=33595.
The problem is that, when trying to unset the parent object in a parent/child relationship, the memory space for the parent reference in the child isn't removed. The problem, left unchecked can cause a script to go over the memory limit pretty easily (especially with larger objects).
He suggests two solutions - one that the user can control (calling a destructor before unsetting the object) or a PHP internals method that involves fixing issues with the reference counts created with the objects.
voice your opinion now!
memory leak object php5 reference parent child release memory leak object php5 reference parent child release
Mike Lively's Blog: Late static binding....sorta /
by Chris Cornutt September 27, 2007 @ 12:58:00
Mike Lively is happy about one thing - that late static binding (definition) has been committed and will be included with PHP 5.3. Unfortunately, he has a downside too:
The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.
He talks about the original intention of the functionality (flexible inheritance for static methods/properties/constants) and how it was implemented, but with one small issue - that "static will ALWAYS return the 'resolved' name of the class used to call the current function". He illustrates with a code example showing an extended class returning a static property.
He also mentions two suggestions to help fix this issue:
- setting the behavior of parent:: such that it forwards the calling class through the next function call.
- introducing another scope [...] using a new keyword so parent:: could remain the same
voice your opinion now!
late static binding patch missing functionality parent inheritance late static binding patch missing functionality parent inheritance
|
Community Events
Don't see your event here? Let us know!
|