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

Dynamic
  • 5,746
  • 9
  • 45
  • 73
kdub
  • 119
  • 4
  • This question isnt very clear. Do you mean the 'command line' version of PHP, or just the operating system's command line? – GrandmasterB Mar 14 '12 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 '12 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. – GrandmasterB Mar 14 '12 at 22:18
  • ughhhhhhh. php shouldn't belong as a programming language, let alone used on a console. – Thomas Eding Mar 15 '12 at 19:28
  • @trinithis, let me guess, you're from an object oriented, strongly typed language, huh. – kdub Mar 15 '12 at 19:44
  • @kdub Yeah, but I just think PHP is a cesspool. I like OO, procedural, and functional languages. Haven't really gotten around to Prolog though... The only thing I dislike more than PHP is MS Internet Explorer. Programming for it with any language (JS, HTML, CSS) is like programming for an alien mothership. – Thomas Eding Mar 15 '12 at 19:51
  • @trinithis. Yeah I've known a few Java, C# developers that feel like you, however...it's just a matter of preference...the overhead with PHP isn't nearly as high with the .Net library. Not too familiar with Java, so can't really say. – kdub Mar 15 '12 at 22:49

3 Answers3

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";
ZJR
  • 6,301
  • 28
  • 36
  • I would add dealing with source control, and dependencies through http://getcomposer.org. – Svish Dec 17 '13 at 09: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.

  • can you elaborate on the tools bundled with web frameworks? – kdub Mar 14 '12 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. –  Mar 14 '12 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.

iglen_
  • 101
  • 2