News Feed
Sections




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

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

Cal Evans:
Signaling PHP
October 28, 2013 @ 09:21:42

Cal Evans has a new post to his site today about a book he's published covering a topic not really focused on in the PHP world - command-line usage. The book, "Signaling PHP" covers the use of the process control extension to handle command-line signals.

Most of the PHP I write these days is CLI scripts. I really wanted to be able to trap signals in some of my scripts. I struggled with this for a while; I even spent an entire weekend googling and reading only to find out that most of the information out there was either wrong, confusing, or incomplete. I decided that once I figured it out, I was going to put everything I learned together in one place to help others that were struggling with this topic as well.

The eBook is available for purchase and download now at a suggested price of only $5 USD. If you've been looking for a quick, concise guide to using process control in PHP, you should check it out.

0 comments voice your opinion now!
signaling ebook calevans cli commandline

Link: http://blog.calevans.com/2013/10/27/signaling-php/

Smashing Magazine:
Powerful Command Line Tools For Developers
October 30, 2012 @ 10:18:56

On the Smashing Magazine site today they've posted a list of powerful CLI tools that every developer should at least know about to help make their lives easier - six of them ranging from SSH tunnels to HTTP testing.

Good tools are invaluable in figuring out where problems lie, and can also help to prevent problems from occurring in the first place, or just help you to be more efficient in general. Command line tools are particularly useful because they lend themselves well to automation and scripting, where they can be combined and reused in all sorts of different ways. Here we cover six particularly powerful and versatile tools which can help make your life a little bit easier.

The tools they mention are all things you'd install on a unix-based system:

  • Curl
  • Ngrep (network packet searching)
  • Netcat (to work with network connections)
  • Sshuttle (SSH tunneling)
  • Siege (HTTP benchmarking)
  • Mitmproxy (capturing proxy, both HTTP and HTTPS)
0 comments voice your opinion now!
commandline cli tools developer list curl ngrep netcast sshuttle siege mitmproxy


Chris Jones:
Using the PHP CLI Webserver to Identify and Test Memory Issues in PHP
August 15, 2012 @ 08:35:07

Chris Jones has a new post today showing how you can use PHP 5.4's built-in web server to help test for memory issues in your application (and the language).

Rasmus mentioned on IRC how he ran the [command line] tests: simply renaming the ".phpt" test files as ".php", and invoking them through the CLI webserver. The SKIPIF sections get executed, but that doesn't affect the desired outcome of testing multiple HTTP requests with different input scripts. [Here] are some quick shell scripts I put together to automate testing the OCI8 extension with valgrind.

He uses the OCI8 extension as an example, showing how to set up these scripts to enable the execution of the tests, fire up the web server and execute Valgrind to help monitor the memory of the execution.

0 comments voice your opinion now!
builtin webserver cli test unittest phpt tutorial shell


Odafe Ojenikoh's Blog:
Interactive PHP CLI Applications using Zend Form
February 16, 2012 @ 11:09:57

Odafe Ojenikoh has submitted a post he's written up showing how to create a command line PHP application with the help of the Zend Framework and it's Zend_Form elements.

Over the weekend, I was toying with the idea of interactive cli applications using readline() and Zend Form for validating input. My motivation for using Zend Form or rather Zend Form elements was to exploit the power of features such as labels, validators, filters and the prospect of reusing forms within web application code.

His example code defines a Filter for the form errors (returning them as a string) and a "Cli" class that handles the interaction with the command line. Next up is a class defining the form elements - a prompt for a color name and either of the words "thank" and "you". The Cli class transforms the form elements into prompts on the command line and lets you define validators to check their input.

0 comments voice your opinion now!
zendform zendframework cli commandline application tutorial


Chance Garcia's Blog:
MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness)
November 09, 2011 @ 11:37:34

Chance Garcia has a recent post to his blog showing how he fixed an issue with his MAMP install involving development of a SSH wrapper he developed and some testing out of PHPStorm and PHPUnit.

One thing I can say is that, even though I use a convenient app like MAMP PRO to set up my local development environment, I'm glad my sysadmin-fu is up to snuff enough to fly without the conveniences because after this ordeal, I feel like I might as well have made my MAMP stack from scratch with all the hoops I jumped tonight.

He shares a few of the things he discovered along the way like: the location of MAMP's "pecl" command, an error caused by a bad pear.conf file, doing custom compiles of PHP and libssh as a fallback and getting the extension to work in the CLI PHP version too.

0 comments voice your opinion now!
osx cli mamp tutorial libssh pecl install configure compile


Gonzalo Ayuso's Blog:
Building a small microframework with PHP (Part 2). Command line interface
August 29, 2011 @ 13:19:11

Continuing on with his previous investigations into microframworks and what it takes to create them, Gonzalo Ayuso has posted his second part of the series - a look at working on the command line.

In my last post we spoke about building a small microframework with PHP. The main goal of this kind of framework was to be able to map urls to plain PHP classes and become those classes easily testeable with PHPUnit. Now we're going to take a step forward. [...] It's pretty straightforward to create a command line interface (CLI) for our microframework.

He shows how to use the getopt function and the $GLOBALS superglobal to pull in arguments given to the command line script. He hooks this into the framework and makes it possible to define the controller and action to execute (with a few examples to show it in action). You can find this updated code on his github account.

0 comments voice your opinion now!
microframework exercise cli commandline parse tutorial


Stuart Herbert's Blog:
Introducing phix
March 21, 2011 @ 08:24:05

In a new post to his blog Stuart Herbert has introduced phix, a packaging tools that can be used to manage and install different components in a framework-agnostic sort of way.

phix is a small command-line tool for PHP applications. I created it to fix (pun intended) the problem of how to easily automate the tasks involved in creating and (especially) maintaining components. These tasks aren't built into phix; they are commands that ship with the phix distribution. You can create your own commands to run inside phix too, and it's easy to do so

The phix tool (easily installed from PEAR) lets you either use built-in commands or custom ones to manage libraries with a few different kinds of commands - current status, initialize a library, upgrade a library and manage the full web application. As of the time of this post, the current version is phix-0.10.4.

0 comments voice your opinion now!
phix library management commandline cli framework agnostic


Simas Toleikis' Blog:
Writing a PHP daemon application
January 19, 2011 @ 11:51:34

Simas Toleikis has a new post today looking at a method he's found for creating a simple daemon application in PHP. He gives you the basic outline of how it works (with a bit of code included) but not a specific example.

There is a special group of applications that require a different PHP script execution model. [...] All of [these special] applications need to be run in the background as daemons - something that PHP was never designed/supposed to be good at. The plain C language is a weapon of choice when it comes to writing a daemon implementation, but then again, if the application in question does not depend on high performance and concurrency - PHP can do the job quite well.

He talks about using the command line interface to run the scripts, creating the while loop to keep execution going and creating the non-blocking socket so that the script can accept new client connections. He also mentions using upstart to run the script in the background and the proctitle PECL extension to give the process a custom name in the process list. He also touches on log files and forking/parallel processing.

0 comments voice your opinion now!
daemon application tutorial proctitle cli upstart


PHPBuilder.com:
Running PHP and Zend Framework Scripts from the Command Line
January 05, 2011 @ 09:29:39

New on PHPBuilder.com today there's a tutorial from Jason Gilmore about running Zend Framework-based applications from the command line in a more hard-coded way than using Zend_Tool.

I regularly use an alternative application of PHP and I'm quite surprised that this capability remains relatively unknown. I'm referring to the ability to run PHP scripts from the command line using its command line interpreter (CLI). Even though it's been possible since the PHP 4.3.0 release, you may be completely unaware of this CLI usage unless you employ great tools such as PHPDoc, Phing, or PHPUnit. Running PHP scripts with CLI allows you to leverage your PHP language skills whenever you need to run scripts from the shell.

He talks about what the CLI functionality of PHP is and what it has to offer the developer. He then creates a few sample scripts so you can get a feel for how to write and run simple PHP CLI applications. Building on these examples, he creates a Zend Framework-based script that loads in the bootstrap, grabs configuration values and makes a connection to the Amazon Web Services.

1 comment voice your opinion now!
zendframework commandline cli tutorial amazon webservice



Community Events





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


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

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework