I made this widget at MyFlashFetish.com.

Saturday, April 9, 2011

Sample PHP Application: A Simple PHP Command Line-based File Generator


PHP is a great scripting language to build web applications. Despite the sluggish improvement and development towards a more architecturally robust, more feature-rich, and less quick-and-dirty programming language recently, I still love coding bytes in PHP. Some people may think of PHP as the language for programming the web quickly. Write some HTML, embed some javascript, add some CSS, put some PHP code, and voila… a dynamic web page is created. I won’t praise how good PHP is for developing a web application. Several companies may have done that. Name Facebook and Yahoo as examples. With some optimization to native PHP codes, both companies have shown how to use the language to cater to millions of users and run a serious business.
In this post, I’d like to highlight another feature of PHP, the command line interface (CLI). PHP CLI can be an alternative to some administrative tasks. Linux users may have been familiar with shell scripting for carrying out system management and configuration tasks. So, why must PHP? The answer is portability. The same PHP code should work not only on Linux but also on Windows. Some critics may argue that other languages may also have answer for portability. I concur to that criticism while at the same time emphasizing PHP as another viable option.
The application to be shown immediately is a file generator. It will create a file of random content with size specified by user when executing the file. The content consists of alphanumeric ASCII characters that are picked randomly. No newline are included in the file. Yet, user can tweak the application to make the generated output file also include newline.
This application can be useful for those who are learning how to write a command line-based PHP utility and also for others who want to conveniently generate files of various sizes for workload testing purpose.
Source code and snapshots are provided below:
a. Source code: filegenerator.php


If you want to play with this simple application, you can download it directly from the following link:



0 comments:

Post a Comment