1

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.)

7
  • This question isnt very clear. Do you mean the 'command line' version of PHP, or just the operating system's command line? 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
    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. Mar 14, 2012 at 22:18
  • ughhhhhhh. php shouldn't belong as a programming language, let alone used on a console. Mar 15, 2012 at 19:28
  • @trinithis, let me guess, you're from an object oriented, strongly typed language, huh.
    – kdub
    Mar 15, 2012 at 19:44

3 Answers 3

4
  • 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
<?php
  echo "Hello World!\n";
1
  • I would add dealing with source control, and dependencies through getcomposer.org.
    – Svish
    Dec 17, 2013 at 9:28
0

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.

2
  • can you elaborate on the tools bundled with web frameworks?
    – kdub
    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
    Mar 14, 2012 at 22:45
-1
  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, privacy policy and cookie policy

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