News Feed

News Archive
feed this:

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

Cees-Jan Kiewiet:
AWS PHP SDK Asynchronously
June 30, 2015 @ 11:31:15

Cees-Jan Kiewiet has a new post today talking about some interesting trickery he was able to do with the AWS (Amazon Web Services) PHP SDK to allow requests to be made asynchronously.

Just got off the AWS SDK for PHP Office Hour hangout and it was great talking with both team members Jeremy and Michael. And one of the things we talked about was async access to the AWS services using the PHP SDK. The goal of this post is to get the AWS PHP SDK client working asynchronously.

He starts with brief instructions on getting the SDK installed (via Composer) along with a library of his own that brings in a few other dependencies. The ReactPHP event loop is what makes the asynchronous connections possible. He includes the code to create the new handler stack and how to use it to make the asynchronous calls. A demo screencast is also included in the post to illustrate the output from a simple set of requests.

0 comments voice your opinion now!
aws amazon sdk asynchronous connection reactphp event loop tutorial


Julien Pauli:
On PHP function calls
January 22, 2015 @ 09:58:39

Julien Pauli has a new post today sharing an interesting function optimization he found using the Blackfire execution profiler.

This blog post is a technical explanation of a PHP optimization found with BlackFire profiler into a PHP script. The related post is located here :

He found that a replacement of a call to strlen with an isset optimized the script by about 20%. It's not typical though, he explains. He points out that the optimization worked so well because the call was part of a loop. He gets into some of the "under the covers" details of why this speed boost happens and even includes the op code output showing the difference. He then starts getting deep into the internal code for PHP and walks through each step made in the evaluation of a string's length. He finishes the post looking at isset (not technically a function) and how it handles its data checking. He also includes information about opcode caching and how to best maximize its impact.

0 comments voice your opinion now!
function call strlen loop isset internals opcode cache performance

Say Hello to Boris A Better REPL for PHP
April 02, 2013 @ 10:34:00

On today Shameer C has a new tutorial introducing you to Boris, a REPL (read-eval-print loop tool) that's a bit more enhanced than the basic PHP interactive shell.

As web developers, we know the importance of the JavaScript console provided by the browser in testing out code snippets. We don't need to write an entire HTML page and JavaScript code just to verify the functioning or logic of a small routine we wrote. Instead, we simply run the expressions in the console and immediately see the results. Similarly, a REPL (Read-Eval-Print Loop) is the console of a programming language in which we can write code line-by-line and see what it does. [...] PHP's REPL is very good in what it does, although it does have some limitations. [...] And so, Boris tries to solve these problems and other concerns as well.

He walks you through the installation (via a git clone and, later, through Composer) and shows how to run it as well as some sample output. He also shows how to make a custom command-line Boris runner and how to embed it into your application. His example of a tool that would benefit from this is a command-line web service client using Boris and Guzzle.

0 comments voice your opinion now!
boris repl read eval print loop tool commandline github
Learning Loops
December 15, 2011 @ 10:15:00 has a new introductory tutorial for those just starting out with PHP (or with programming really) talking about using looping structures for sets of data - for, while/do-while and foreach.

A significant advantage of computers is that they can perform repetitive tasks easily and efficiently. Instead of writing repetitive code you can write a set of statements that processes some data and then have the computer execute them repeatedly by using a construct known as a loop. Loops come in several different flavors in PHP: for, while, do-while, and foreach. I'll introduce you to each of them and show you how they can making repetitive tasks straightforward and easy to maintain.

The tutorial explains a use case for each of the loop types and includes a bit of sample code showing how to put it into practice. It also shares two special keywords that can be used to bypass or break out of your current loop - break and continue.

0 comments voice your opinion now!
introduction tutorial loop dataset for while foreach break continue

Gareth Heyes' Blog:
Non alphanumeric code in PHP
September 23, 2011 @ 10:05:47

Gareth Heyes has tried out an interesting experiment - running non-alphanumeric code in PHP using only octal escapes.

So a small php shell was tweeted around and it inspired me to investigate a way to execute non-alphanumeric code. First off I started with the idea of using octal escapes in PHP and constructing the escape so for example: 107 is "G" if I could construct the "107" and add the backslash to the beginning maybe I could construct "G".

A snippet of example code is included showing his octal-based code for creating a "G" (6 lines of pluses, parentheses, equals and a few more characters). By doing some trickery with bitwise operators on strings, he was able to combine characters and make the string "GET". Pretty clever, even if it's not entirely practical.

0 comments voice your opinion now!
nonalphanumeric code shell loop octal
Quick Tip Loop Through Folders with PHP's Glob()
April 27, 2010 @ 11:49:15

Sometimes when you're looking through the filesystem in your PHP application, you just need a quick and easy way to grab a file listing from a directly and move on. Sure, you can use the usual opendir and readdir combo to loop through the files, but there's another function that might suit your needs better - glob. In this quick tutorial from today they show you how it works.

Are you still using opendir() to loop through folders in PHP? Doesn't that require a lot of repetitive code everytime you want to search a folder? Luckily, PHP's glob() is a much smarter solution.

They include code examples showing how the usual opendir/readdir code can be translated over to an example using glob and mention the two arguments you can use - a pattern-matching search string and a modifier to change settings on the search and on the results returned.

0 comments voice your opinion now!
glob tutorial loop filesystem opendir readdir
Loops & Decisions in PHP - The ABC's of PHP Part 8
May 07, 2009 @ 10:26:34 has posted the eighth part of their introductory "ABCs of PHP" series today. This time the focus is on looping and decision functionality (like if/while/for/etc).

n any given computer language (PHP is no exception) there has to be a way to allow the running code to decide between doing 2 different things. If there wasn't then software would not be able to adapt based on operating conditions, or it wouldn't be able to decide between two different users.

They look at using: if statements and operators, for loops and while loops. When they look at the operators, they talk about the differences between equals/not equals, grater than/less than and two of the boolean operators - AND and OR.

2 comments voice your opinion now!
loop decision if while for operator tutorial introduction beginner

Jani Hartikainen's Blog:
Closures coming in PHP 5.3 and that's a Good Thing
February 20, 2009 @ 14:05:56

Jani Hartikainen takes a look at closures in a new post to his blog - why their good and why they can help you more than you know.

PHP 5.3 will be introducing closures to PHP. Closures, also known as anonymous functions, will allow you to declare functions "inline" and store them in variables. While the syntax may seem a bit weird compared to how it is in languages like JavaScript, closures will be a useful addition to the language. However, like reflection, it's a feature that may not immediately show it's usefulness...

He explains what they are (a sort of anonymous function) and a simple example of them in use - a function that works with data from an array to display each of the rows with the given "formatter" function. Another brief example is a method of using them in PHP functions like array_map and usort as an argument for the callback parameter.

0 comments voice your opinion now!
closure php5 good anonymous function example row loop callback

Leonid Mamchenkov's Blog:
Perl vs. PHP variable scoping
December 12, 2008 @ 08:49:14

Leonid Mamchenkov has compared Perl versus PHP in this new blog post - specifically how they handle variable scoping.

I've mentioned quite a few times that I am a big fan of Perl programming language. However, most of my programming time these days is spent in PHP. The languages are often similar, with PHP having its roots in Perl, and Perl being such a influence in the world of programming languages. This similarity is often very helpful. However there are a few difference, some of which are obvious and others are not.

His example compares looping (a foreach in both) and how, after the Perl loop the $value variable is no longer accessible. In PHP, however, it's passed back out into the current scope and can be read just like any other variable. While this can be useful, it can also cause headaches when trying to track down elusive bugs.

1 comment voice your opinion now!
variable scope foreach loop local outside compare

Simple Easy Parallel Processing in PHP
September 10, 2008 @ 09:33:51

John Lim has a new blog post today sharing his method for simulating parallel processing inside of a PHP application.

One problem we were having is that some of our batch processing jobs were taking too long to run. In order to speed the processing, we tried to split the processing file into half, and let a separate PHP process run each job. Given that we were using a dual core server, each process would be able to run close to full speed (subject to I/O constraints).

He shows the two "jobs" files that just echo out the job name and the number of seconds it's been running and the "control.php" that makes use of streams (pointed at localhost) to start the jobs apart from the main script. Another function checks the stream resource to see if it gets an EOF from it and returns back the output.

0 comments voice your opinion now!
parallel processing tutorial stream job loop eof

Community Events

Don't see your event here?
Let us know!

project podcast framework testing yii2 application opinion symfony php7 series community language interview list introduction api composer laravel part2 example

All content copyright, 2015 :: - Powered by the Solar PHP Framework