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: