I started with PHP a little while ago. I've been doing a lot of tutorials, practice sites, etc. and it's going great.

One thing I like about PHP is how easy it is to get started (downloading WAMP and voila). However, up until I learned about PEAR and MVC frameworks, I haven't put much thought in using a command line Interface for PHP development...

I've not really used the command line that much and it will take me some getting used to, so a couple of questions I have are:

What are the most common uses of the Command Line when developing websites and web applications with PHP?

Can you run MVC frameworks such as Zend, CakePHP, etc without ever using it?

Besides PEAR, are there any other PHP repositories that use the command line to work?

(It seems if you want to avoid using PEAR there are countless other PHP Classes/libraries on the internet that one could download and then simply copy and paste files into your site.)

  • This question isnt very clear. Do you mean the 'command line' version of PHP, or just the operating system's command line? Commented Mar 14, 2012 at 21:36
  • Sorry if it wasn't clear...I'm pretty sure I mean 'the operating system's command line'...If you're a PHP developer and you are building web applications, when will need to use the command line? One answer could be: If you want to work with PEAR packages. But I am just looking for some common uses.
    – kdub
    Commented Mar 14, 2012 at 21:43
  • You need the operating system's command line whenever you need to do something in the operating system. For exmple, restart apache, make users, recompile php, set up cron jobs.. etc. If all you ever do is save php files from your editor, and you dont need to manage the server, you probably wont need the command line much. Commented Mar 14, 2012 at 22:18
  • ughhhhhhh. php shouldn't belong as a programming language, let alone used on a console. Commented Mar 15, 2012 at 19:28
  • @trinithis, let me guess, you're from an object oriented, strongly typed language, huh.
    – kdub
    Commented Mar 15, 2012 at 19:44

3 Answers 3

  • background processing (yep, it's quite ugly)

    <?php system("php background-process.php &");

  • putting php jobs (e.g. db maintenance?) into cron tables

  • cgi processing in unsupported web servers
  • linting before uploading

    php -l file.php

  • fast checkup of daring language constructs

    php.exe -r "$a=array(1,6,9); array_splice($a,2,1,array(9,10,46)); var_export($a);"

    php -r '$a=array(1,6,9); array_splice($a,2,1,array(9,10,46)); var_export($a);'

  • testing backend code during development

...and then, I also do shell scripting in php.

#!/usr/bin/env php
  echo "Hello World!\n";
  • I would add dealing with source control, and dependencies through getcomposer.org.
    – Svish
    Commented Dec 17, 2013 at 9:28

PHP is generally best suited to web development even though it has been adapted for other purposes. Common use on the command line is likely to be in the context of web development, particularly working with tools that are bundled with web frameworks such as the CakePHP console.

  • can you elaborate on the tools bundled with web frameworks?
    – kdub
    Commented Mar 14, 2012 at 22:23
  • 1
    By "tools bundled with web frameworks" I mean utilities for generating boilerplate code, database schema, scaffolding, etc as part of the development process.
    – user49491
    Commented Mar 14, 2012 at 22:45
  1. What are the most common uses of the Command Line when developing websites and web applications with PHP?

    Some. When you want to develop a web service that doesn't necessarily need an interface, like an auto response system to sms/emails, I would recommend writing an application that runs on the console. These are background processes generally.

  2. Can you run MVC frameworks such as Zend, CakePHP, etc without ever using it? From a Zend perspective: you can run the Zend framework without the console. The console only makes work a little easier, reduces repetition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.