News Feed

News Archive
feed this:

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
December 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.

0 comments voice your opinion now!
command line cli symfony console tutorial

Read Line From File (stream_get_line)
April 23, 2009 @ 09:36:51

The 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.

0 comments voice your opinion now!
stream tutorial file line read streamgetline

Solar Blog:
Solar CLI - Make-Model
March 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).

0 comments voice your opinion now!
solar framework command line makemodel model mysql tutorial

Using the Xdebug Extension's xdebug_call_function() Function
February 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.

0 comments voice your opinion now!
xdebug call function file line debugger extension

Richard Heyes' Blog:
Reading a specific line in a file
April 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.

1 comment voice your opinion now!
reading specific file line example class

SitePoint PHP Blog:
PHP Manual CLI style 2.0
November 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 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.)

0 comments voice your opinion now!
command line manual bash script command line manual bash script

Mikko Koppanen's Blog:
Creating a simple line graph
October 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.

1 comment voice your opinion now!
imagick image output graph line tutorial imagick image output graph line tutorial

Christian Wenz's Blog:
phpa-norl, a phpa port for Mac OS X and Windows
July 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.

1 comment voice your opinion now!
phpanorl command line shell interactive macosx windows phpanorl command line shell interactive macosx windows

Felix Geisendorfer's Blog:
Command line fun in CakePHP 1.2
October 16, 2006 @ 07:18:32

On his ThinkingPHP blog today, Felix Geisendorfer hands out mor eCakePHP goodness with some talk about working with the popular CakePHP framework in an unlikely place - on the command line with the "bake" utility.

The "bake" utility is included with the CakePHP distribution and helps a developer scaffold out an application with minimal effort. Things have been changed in the recent distributions, though:

Unlike the old bake.php, which was only used to auto-generate code for you, this one follows a much cooler concept. The main idea is to have an interface to a wide variety Tasks.

The new and improved "bake" program takes the tasks created and builds out a bit more functionality than just the scaffolding as the version before did. Felix includes an example of a task (a simple echo) just to show how it's formatted.

0 comments voice your opinion now!
cakephp framework task bake command line scaffold cakephp framework task bake command line scaffold
PHP on the command line
March 13, 2006 @ 07:26:42 has posted another new tutorial, this time they look at the command-line, providing the basics to those that have only used PHP in the web-based world.

PHP is traditionally only used on the internet to power our websites, but it's also capable of doing more. Since version 4.3 PHP ships with a special version which can be used to execute scripts on the command line, and do certain system tasks. If you're a Linux user, you probably know what the command line is, but if you're a Windows user you might not.

They show the code/commands in the examples they give in the context of it running on a Windows machine, but it's not a far leap to work with it on a unix-based system as well. They start with the basics - how to get to it, how to use it - before moving on to other features, like taking in arguments. They wrap it up with a sample application, a calculator, that can do the four basic operations on the two numbers entered.

0 comments voice your opinion now!
command line tutorial introduction beginner command line tutorial introduction beginner

Community Events

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

series testing community framework podcast refactor code opinion release interview unittest install laravel configure wordpress language introduction threedevsandamaybe list developer

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