The most common usage of PHP is development of web applications. The PHP CLI SAPI - server application programming interface provides development of command line applications.
You can use PHP to write command-line applications as well.
Some useful libraries: