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

Knp University:
Fun with Symfony's Console Component
Oct 06, 2015 @ 15:26:41

In a post to the Knp University blog they show you some of the fun you can have with the Symfony Console component in a single file including a few lesser known (and lesser used) features.

One of the best parts of using Symfony's Console component is all the output control you have to the CLI: colors, tables, progress bars etc. Usually, you create a command to do this. But what you may not know is that you can get to all this goodness in a single, flat PHP file.

They walk you through the creation of a ConsoleOutput object with a simple writeln output of a formatted method. They briefly mention the handling for changing up the output (OutputFormatter and OutputFormatterStyle) before getting into something a bit more complex - table layouts. They end the post with an interesting "hidden" feature inside the component, the Symfony track progress bar (animated gif included to show the end result).

tagged: symfony console component feature pretty output table track progressbar

Link: http://knpuniversity.com/blog/fun-with-symfonys-console

Displaying stream progress in PHP
May 27, 2015 @ 13:39:26

Hannes Van De Vreken has posted a tutorial to his site showing users of the Symfony Console component how to show progress on a stream using the ProgressBar helper and a bit of code to inspect the stream itself.

With PHP you can, next to handling HTTP requests, invoke scripts from the command line. [...] The Symfony console component is a very useful tool to define and invoke these kind of CLI tasks. [...] What is actually printed on the console is very important for the issuer of the task. Think of it as the command’s usability. Too little runtime information, the less usable the task. [...] Enter the ProgressBar. The ProgressBar is an output helper that wraps the OutputInterface object.

He talks briefly about how the ProgressBar helper works in the console component's output and gives a simple example of the output. He then shows how to hook it into a bit of PHP using the stream_notification_callback optional parameter (defined in stream_context_create) to point to another class method that handles the progress bar updates. It performs a bit of introspection on the stream and updates the progress as its contents progress. He does point out a few caveats though, including that the transfer is not made asynchronous by this handling.

tagged: symfony console stream progress progressbar helper tutorial

Link: https://hannesvdvreken.com/2015/05/12/stream-progress/

SitePoint PHP Blog:
Symfony2 Console: Getting Started with Console Helpers
Apr 09, 2015 @ 15:44:03

If you've ever worked with the Symfony Console component and wanted to enhance the experience with some additional functionality, check out the latest tutorial from the SitePoint PHP blog: Symfony2 Console: Getting Started with Console Helpers.

In this tutorial, I’ll share my experiences and we’ll give some extra love to the console helpers, which provide us with a large collection of handy functions. There are a lot of reasons to create console commands in your projects: sending emails, exporting/importing data, creating users, and so on. [...] By the end of this post, we want to be able to create a basic console command to generate some output – any output will do – only the way to getting there is important. Near the end, we’ll discover some console helpers in order to create some nice interactions between users and the interface.

He starts by helping you get the component installed via Composer and creating the first simple command line script (a ConsoleApplication). He shows how to add in a basic "hello world" command (conveniently named "BasicCommand") and the result when executed. With this in place, he starts in on three helpers:

  • Question Helper
  • Table class
  • Progress Bar

Each includes the code needed to implement it and the resulting output. You can find out more about the component in the Symfony2 documentation.

tagged: symfony2 console tutorial command helpers introduction question table progressbar

Link: http://www.sitepoint.com/symfony2-console-getting-started-console-helpers/

PHPMaster.com:
Tracking Upload Progress with PHP and JavaScript
Feb 06, 2012 @ 19:58:32

In a new tutorial today from PHPMaster.com, they show you how to combine Javascript and a PHP feature to track the progress of an upload to your web application.

A problem that has plagued web developers for years is how to add real-time information to their applications, such as a progress bar for file uploads. [...] JavaScript can access a file’s name, type, and even the width and height of a local image, but it wasn’t until HTML5 that it could access a file’s size. [...] In this article I’ll show you how [the session.upload_progress] feature can be used to create a simple upload progress bar without any external libraries or browser dependencies.

The tutorial provides all the steps you'll need to get it working - defining the form with the extra required field, styling it and plugging the Javascript in to call a small script to get the progress of the upload. It returns the difference between the content-length of the file and the current size (as a percentage of 100).

tagged: track upload progress extension javascript tutorial progressbar

Link:

Dave Marshall' Blog:
Asynchronous cache priming with progress bars via Gearman, Memcache and Dojo
Apr 04, 2011 @ 15:18:20

Dave Marshall has written up a new post showing how he's used memcache, Gearman and Dojo to create an asynchronous progress bar he uses when generating large reports.

I have a (highly optimised) report that takes way too long to generate, up to around 30 seconds. [There's] too many variables to prime caches for every possible combination [and] personally, I don’t think the browsers inbuilt progress bar is enough feedback for todays web users.

He generates the data into memcache when the user requests it and uses the Gearman worker processes to handle requests for data that doesn't yet exist. The progress bar is a part of Dojo and uses the dijit.ProgressBar widget to keep checking the progress of the build. This way the user can even leave the page and come back if the process takes too long with no threat to the generating report. You can find all of his code he's used to make it happen on his github account.

tagged: gearman tutorial memcache dojo progressbar generate report

Link:

Brian Moon's Blog:
PHP command line progress bar
Mar 11, 2010 @ 16:23:41

Brian Moon has a quick post that links to a but of code that gives you a progress bar for the command line that's flexible enough to be used in an number of situations.

Was just looking through some code and came across this function I wrote some time ago. If you do a lot of your processing scripts in PHP like we do, you probably need to know what is going on sometimes. So, I made a progress bar for use on the cli. I thought I would share it.

You can see a demo of it here (screencast) or just download the code. Comments on the post also point out the PEAR Console_Progressbar package and the ez Components class for creating a more advanced progress bar.

tagged: progressbar commandline cli screencast

Link:


Trending Topics: