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

Master Zend Framework:
The Composer Command-Line Essentials
Nov 29, 2016 @ 16:15:52

The Master Zend Framework site has posted a tutorial that seeks to help you get the most out of Composer on the command line with some essential tips beyond just he basics.

I know that a series on Composer might seem odd. But, as Composer’s been a part of PHP for so long now, I feel that it’s something which most of us take for granted. It’s revolutionised the PHP landscape, making it easier than ever before to build great software in PHP. But do we really know how to get the most out of it. For that reason, I’ve created this series, so that you level up your skills and really get the most from it.

In part one of this series, I’m going to take you through Composer’s command-line. I’ve cherry-picked a key subset of the command-line options, and focused in on key switches, so that you can do more than you already can.

He skips over the basic "require", "install" and "update" handling covered in many other tutorials and instead covers:

  • project creation
  • the "show" command to list installed packages
  • "remove" to drop a package from the current dependencies
  • using "depends" to see package dependencies
  • finding outdates packages with (appropriately) the "outdated" command
  • seeing suggested packages with "suggest"

For each item on the list there's an example of the command, what kind of options is allows and, for some, the output generated as a result.

tagged: composer command line advanced commands tutorial

Link: http://www.masterzendframework.com/series/tooling/composer/command-line-essentials/

Joshua Thjissen:
Benford’s law in frameworks
Dec 10, 2015 @ 17:10:50

Joshua Thijssen has an interesting post to his site talking about Benford's Law, related to digits and how frequently they would appear in results based on significance.

In a new talk I’m currently presenting at conferences and meetups, I talk – amongst other things – about Benford’s law. This law states that in natural occurring numbers, the first digit of those numbers will most often start with a 1 (around 30% of the time), and logarithmically drops down to the number 9, which occurs only 5% of the time.

[...] Even though there is no guarantee that something will actually follow Benford’s law, a lot of things do, and in fact, it can be used for things like fraud detection: in your taxes, in elections, but basically anything concerning numbers. [...] But anyway, I wanted to see Benford’s law in action for myself, so I’ve come up with a simple test: Take a (PHP) framework, and count the line-numbers for each PHP file in the framework.

He shares the script (well, command) he uses to get these counts and how he did the sorting to help make some sense out of the results. He includes some of the results and graphs showing them to help visualize the Benford’s "curve" the results take. Interestingly enough, most of them follow the trend very closely with only slight variances for Zend Framework v2 and only them because it fluctuates more, nothing to do with the quality of the framework.

tagged: benfordslaw trend line count framework graph results

Link: https://www.adayinthelifeof.nl/2015/12/09/benfords-law-in-frameworks/

SitePoint PHP Blog:
Command line PHP using Symfony Console
Dec 12, 2013 @ 16: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 @ 14: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 @ 16: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 @ 18: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 @ 17: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 @ 15: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 @ 15: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 @ 17: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:


Trending Topics: