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

Davey Shafik:
An Exceptional Change in PHP 7.0
Jul 31, 2015 @ 09:55:37

Davey Shafik has a post today that talks about an exceptional change to PHP 7.0 and some updates that have been made to provide more of a hierarchy (a different one) that can make them easier to work with.

With PHP 7 errors and exceptions are undergoing major changes. For the first time, the PHP engine will start to emit exceptions instead of standard PHP errors for (previously) fatal, and catchable fatal errors. This means that we can now handle them much more gracefully with try... catch. But with this change, comes a whole new exception hierarchy.

He provides a tree of the error/exception relationships, what they inherit from and who their "children" are. He also talks more in detail about the "error" type exceptions: Error, AssertionError, ParseError and TypeError. He gets into more detail about catchable fatal errors and the userland handling of the Throwable type and extension.

tagged: exception change php7 throwable error exception tree parent child

Link: http://daveyshafik.com/archives/69237-an-exceptional-change-in-php-7-0.html

SitePoint PHP Blog:
Laravel Blade Recursive Partials with @each
Apr 02, 2015 @ 08:21:50

On the SitePoint PHP blog there's a post from editor Bruno Skvorc showing you how to create recursive partials in Blade, the templating library that the Laravel framework uses internally for rendering output.

n this tutorial, we’ll go through the process of implementing recursive partials in Laravel’s Blade templating engine by means of the @each command. This will allow us to render data structures with an arbitrary number of nested children without needing to know the maximum depth of the array.

In his example, he's rendering the data from a nested set, a folder structure that could potentially go many levels down. He gives an example of the data he's working with in PHP arrays and how it could be outputted in plain old PHP. Of course, things have to be done a little differently in Blade and he includes the templates to do it - the main level and a partial that's used to output the folder information. He shows the use of "@each" in these examples and explains how it works and an example of the output.

tagged: laravel blade recursive child template tutorial example

Link: http://www.sitepoint.com/laravel-blade-recursive-partials/

Master Zend Framework:
HowTo Use Child and Segment Routes to Build Simple Routing Tables
Apr 03, 2014 @ 11:15:05

Matthew Setter has a new post to his Master Zend Framework site today showing you how to use child and segment routes to create a routing table in your Zend Framework v2 application. These routes are "sub-routes" underneath a main route defined in the main router configuration.

Routing is one of the key requirements in modern applications, especially in Zend Framework 2; but they shouldn’t be overly-complicated. Today, we’re going to look at how to build a routing table, simply and easily using child and segment routes. [...] But how would we do that? Gladly, it’s quite simply, using a combination of [the] two route types: Segment and Child Routes. I’ve made a complete example, which’s available in this Gist. Feel free to skip straight to that. But otherwise, let’s step through the annotated version together.

He sets the stage with an example in a "writing pipeline" application that helps him predict his income from his freelance writing. He describes the main controllers and the routing configurations they might share. In his example code, he shows how to define the routes and modify them to use segments and child routes to handle constraints. There's also a section about extracting out the segments from the route.

tagged: child segment routes tutorial routing zendframework2

Link: http://www.masterzendframework.com/tutorial/child-and-segment-routes

Rob Allen's Blog:
Access view variables in another view model
Apr 03, 2012 @ 12:53:37

In this new post to his blog Rob Allen shows you how to access the view variables from another ViewModel.

Unlike Zend Framework 1, the view layer in Zend Framework 2 separates the variables assigned to each view model. This means that when you are in the layout view script, you don't automatically have access to variables that were assigned the the action's view model and vice versa.

He includes snippets of code with an example controller and a sample view that fetches a value from a child ViewModel instance. He also shows how to access layout and configuration values in the view.

tagged: view model variables other scope child viewmodel zendframework2

Link:

Re-Cycled Air Blog:
PHP Dark Arts: Daemonizing a Process
Oct 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.

tagged: daemon process child parent tutorial

Link:

Padraic Brady's Blog:
Mysteries Of Asynchronous Processing w/PHP - Pt 3: Spawned Child Processes
Oct 01, 2009 @ 12:35:23

Padraic Brady has posted part three of his look at asynchronous processing in PHP applications today. The previous two parts introduced you to the topic and got you ready to work with child processes in a Zend Framework application. This latest part gets into the code showing how to fork the processes and handle communication between them.

With the theory heavy portion of the series out of the way, we can begin to explore the various implementation possibilities. In this part, we will examine implementing Asynchronous Processing using a child process, i.e. a separate PHP process we create from our application during a request. We'll analyse this implementation option before introducing the source code so we may understand its advantages and disadvantages.

He looks at both the advantages and disadvantages of processing with child processes and suggests a method to get a handle on the processes rather than just spawning new processes - forking. Some basic code examples are included, using the popen function to open the new child process and a Zend Framework example.

tagged: spawn child process asynchronous tutorial

Link:

Evert Pot's Blog:
Lighttpd + PHP fastcgi woes
Sep 10, 2008 @ 12:55:05

Recently Evert Pot has been having some issues with setting up lighttpd and PHP (fastcgi) for one of his web servers:

In trying to get more out of our webservers using a Lighttpd and PHP-FastCGI setup, I've come across some major issues that make it difficult to use. I hope this post will warn people of some of the bugs they might encounter and workaround that might need to be implemented until some of these are fixed.

He ran up against two problems - that the parent PHP-CGI process spawns off the configured number of children correctly but with the lighttpd server is killed, they don't get released and that, once you hit full capacity for the PHP backend lighttpd starts serving up 500 errors.

In the comments for the post several others have offered some advice on things that might help (like different config settings and even using XCache to prevent the 500s issue from coming up again).

tagged: lighttpd fastcgi problem capacity error child orphaned

Link:

Jani Hartikainen's Blog:
Understanding Doctrine's NestedSet feature
Sep 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).

tagged: doctrine nestedset feature fetch database row parent child

Link:

Daniel Cousineau's Blog:
Displaying N-Deep Trees (Remember Your Algorithms Course?)
Aug 07, 2008 @ 12:03:23

On his Tower of Power blog Daniel Cousineau has written up a look at using a more detailed categorization method than just a parent/child relationship on your data - Tree Traversals.

If the software calls for only 2 levels of categorization (Parent and Child only), a simple nested for loop will suffice. However, software requirements change and you'll soon find yourself up shit creek without a paddle if you need to support 3 or 4 levels of nesting. [...] To those who's training is less formal (most web developers I meet have practical training, not formal), I'll help you out: Tree Traversals (or if you are completely lost, Recursion).

He creates a recursive function that, when passed in a category set with different types in it, can handle each of them and then calls itself again with the new child data. His sample code creates url out of a set of categories.

tagged: tree category recursion tutorial parent child loop treetraversal

Link:

DevShed:
Defining Public and Protected Methods with Member Visibility in PHP 5
Jun 12, 2008 @ 07:51:13

DevShed continues their series looking at variable scoping in PHP5 classes with this new look at using the public and protected keywords to "restrict member visibility".

Now that you know what will be treated in this fourth chapter of the series, it's time to learn how to declare and implement public and protected methods with PHP 5 classes. Of course, as always I'm going to address this useful topic by using a hands-on approach, which means that there's a bunch of code samples ahead, waiting patiently for you.

They talk about calling methods globally first and then move into the keyword restrictions. They show the difference between a public method/variable and a protected one, including how to get at the protected members from a child class.

tagged: tutorial php5 protected member visibility public child

Link: