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

SitePoint PHP Blog:
Command line PHP using Symfony Console
Dec 12, 2013 @ 10:34:15

The SitePoint blog has a new post from Daniel Gafitescu covering the use of the Symfony Console component to create command line PHP scripts quickly and easily.

As a PHP developer, you will often find yourself working with PHP in the command line. The first time I had to use it was because I would get the "Maximum execution time of 30 seconds exceeded" error on a shared server where you could not change the max_execution_time PHP setting. Nowadays building command line scripts is much easier than it used to be. If you search on Packagist you will find a lot of packages to work with the command line but the one that stands out and is the most commonly used is Symfony/Console.

He starts with what you'll need to add to your Composer configuration to pull in a development version (2.4.x-dev) of the component. With that installed, he sets up a base directory ("/app") and a basic skeleton for your application. For his first command, he creates a script that will calculate the fibonacci numbers between two given numbers. He shows how to work with the input and Output objects inside the script and the code for the finished command - including some screenshots of the output.

tagged: command line cli symfony console tutorial

Link: http://www.sitepoint.com/command-line-php-using-symfony-console/

PHPro.org:
Read Line From File (stream_get_line)
Apr 23, 2009 @ 09:36:51

The PHPro.org website has a quick new tutorial about a method (using streams) to get the information from a certain line of a file.

Reading files in PHP can be a tricky business if not handled correctly. Most often when confronted with reading a line from, the nearest tool to hand is the file() function. The problem with using the file() function is that it reads the whole file into an array, and thus, into memory [...] A better, and more efficient way is to loop through the file stream using the stream_get_line() function. Care still needs to be taken to clear the buffer on each iteration, or the same problem could potentially arise as with the file() method.

The code calls fopen on the file and, while it's not the end of the file, uses the stream_get_line function to grab things a line at a time. This saves you from having to read in the entire file (like with a file_get_contents or file - especially good for large files.

tagged: stream tutorial file line read streamgetline

Link:

Solar Blog:
Solar CLI - Make-Model
Mar 11, 2009 @ 11:12:27

The Solar blog has been updated this a new post continuing on the look at the Solar CLI (started here) and its "make-model" command.

This entry is a continuation of the Solar CLI series--a series that aims to detail Solar CLI commands, available options, parameters, and usage examples. In this entry we take a look at make-model, a command that can generate models based on a SQL table.

The post goes through the available options and parameters that you can give the command to make things easier and includes an example of running the "make-model" on a table in a MySQL database (with the code to add to your Solar configuration file to match).

tagged: solar framework command line makemodel model mysql tutorial

Link:

DevShed:
Using the Xdebug Extension's xdebug_call_function() Function
Feb 09, 2009 @ 12:56:18

This new tutorial from DevShed takes a look at the XDebug debugging tool for PHP and how the xdebug_call_function method allows for even more flexibility in your testing experience.

The Xdebug extension comes equipped with many other functions, however, that allow you to debug PHP applications more deeply. Therefore, in this second article of the series, I'll be discussing how to use another useful function included with the extension, called "xdebug_call_function()," which as its name suggests, can be utilized for keeping track of the functions called by a PHP script.

They start with a look back at two of the other xdebug functions - xdebug_call_file and xdebug_call_line - before showing how to use this new function (xdebug_call_function) to get the function that called your custom handler.

tagged: xdebug call function file line debugger extension

Link:

Richard Heyes' Blog:
Reading a specific line in a file
Apr 07, 2008 @ 12:56:08

Richard Heyes has thrown together some code for a simple thing that he's seen developers request over and over again - moving to/reading from a specific line in a file.

After reading something on the php-general list I decided that a) I'm bored, and b) I'll write something which handles it. So here it is.

His code is simple - looping through the lines of the file until it locates your desired target (with some error checking along the way). Plus, if it's already fetched, it keeps it in a cached array for future retrieval.

tagged: reading specific file line example class

Link:

SitePoint PHP Blog:
PHP Manual CLI style 2.0
Nov 29, 2007 @ 09:35:00

Sometimes, you just can't get to a web browser to look up something from the PHP manual (or might not want to). Another option is the command line and in this new post to the SitePoint PHP blog, Troels Knak-Nielsen shows you a method for getting the entire manual entry right at your prompt neatly formatted.

One thing, I missed with either of the two [other solutions mentioned], was the ability to see the entire manual entry. It's quite often, that the manual actually holds useful information (Who'd known that!), so I find myself using www.php.net a lot. Or I did, until I decided to do something about it. Now, shell-scripting isn't what I spent most of my time on, so it's not with out a bit of pride, that I present to you phpm two-oh.

Most of the rest of the post is his bash script ready top cut and paste as well as some simple instructions on getting it working. (An emacs bonus is also included - a method for binding the script to a key to act on the current word.)

tagged: command line manual bash script command line manual bash script

Link:

SitePoint PHP Blog:
PHP Manual CLI style 2.0
Nov 29, 2007 @ 09:35:00

Sometimes, you just can't get to a web browser to look up something from the PHP manual (or might not want to). Another option is the command line and in this new post to the SitePoint PHP blog, Troels Knak-Nielsen shows you a method for getting the entire manual entry right at your prompt neatly formatted.

One thing, I missed with either of the two [other solutions mentioned], was the ability to see the entire manual entry. It's quite often, that the manual actually holds useful information (Who'd known that!), so I find myself using www.php.net a lot. Or I did, until I decided to do something about it. Now, shell-scripting isn't what I spent most of my time on, so it's not with out a bit of pride, that I present to you phpm two-oh.

Most of the rest of the post is his bash script ready top cut and paste as well as some simple instructions on getting it working. (An emacs bonus is also included - a method for binding the script to a key to act on the current word.)

tagged: command line manual bash script command line manual bash script

Link:

Mikko Koppanen's Blog:
Creating a simple line graph
Oct 15, 2007 @ 12:55:31

Mikko Koppanen has another post to his blog today that once again shows the combination of PHP and Imagick to create/output an image - this time, it's a simple line graph.

This example demonstrates how Imagick can be used to create graphs. This graphing class itself is mostly a demonstrative example. There are also some hardcoded values in the graph (like the steps in the values on the left hand side) but it should not be hard to refine it into a more elegant graphing solution.

The graph is made using the Imagick drawing functions that extends the standard "draw" class. The code produces a graph with a (straight) line drawn from point to point - code and output examples are both included.

tagged: imagick image output graph line tutorial imagick image output graph line tutorial

Link:

Mikko Koppanen's Blog:
Creating a simple line graph
Oct 15, 2007 @ 12:55:31

Mikko Koppanen has another post to his blog today that once again shows the combination of PHP and Imagick to create/output an image - this time, it's a simple line graph.

This example demonstrates how Imagick can be used to create graphs. This graphing class itself is mostly a demonstrative example. There are also some hardcoded values in the graph (like the steps in the values on the left hand side) but it should not be hard to refine it into a more elegant graphing solution.

The graph is made using the Imagick drawing functions that extends the standard "draw" class. The code produces a graph with a (straight) line drawn from point to point - code and output examples are both included.

tagged: imagick image output graph line tutorial imagick image output graph line tutorial

Link:

Christian Wenz's Blog:
phpa-norl, a phpa port for Mac OS X and Windows
Jul 09, 2007 @ 07:58:00

On the Hauser & Wenz blog today, Christian Wenz points out a patched version of the interactive command line PHP client, phpa to work on a Mac OS X machine - phpa-norl.

phpa is an interactive command line shell for PHP by David Phillips. Stefan Fischerlander, usually known as a SEO expert and Perl admirer, has patched phpa for Mac OS X and Windows (the default builds theredo not seem to support a feature required by phpa). The result: phpa-norl. Stefan successfully ran this on OS X, and I could confirm that it runs on Windows, as well

He also mentions some features of the client including a history feature that makes looking back through previous commands simple.

tagged: phpanorl command line shell interactive macosx windows phpanorl command line shell interactive macosx windows

Link: