phpa-norl - PHP shell for Mac OS X and Windows
When writing code I really like to have some kind of fast feedback system, like the Smalltalk workspace or the Python IDLE shell. For Perl development I have created a graphical Perl shell for that purpose.
Because I now have to do more and more work with PHP, I’ve been looking for a similiar tool and came across phpa, “an interactive command line shell for PHP” from David Phillips. Unfortunately phpa needs readline which isn’t available on Mac OS X and Windows. (No, of course readline is available, but you have to compile PHP yourself to use it.)
So, I re-worked David’s PHP shell and removed all the fancy readline stuff. Without readline support the shell isn’t as useful as it could be, but at least it now runs on Mac OS X and I think it will also run on Windows systems. This interactive php shell without readline support I call phpa-norl - where the norl part obviously stands for “no readline” support.

Installation
Download the PHP shell file phpa-norl and start it with php phpa-norl.
To mimic the readline support, there is a simple history function in phpa-norl. Entering a single ‘h’ lists the twenty last commands you executed. Appending a number to ‘h’, executes the command with that number in the history list. ‘h0′ for example always re-executes your last command. You can also enter a multi-line statement. If the last character on your input line is a ‘#’, than phpa-norl assumes that there will follow additional code on a new line. To leave the PHP shell, just enter a simple ‘q’ and phpa-norl will exit.
PHP shell usage
Here is a typical phpa-norl session:
macbook:~ sf$ ./phpa-norl
PHP 5.2.0 (cli) (???) [Darwin]
>>> $a=array(17,899,324,234)
>>> $b=array(288,900,1212,2323)
>>> $c=array_merge($a,$b)
>>> sort($c,SORT_NUMERIC)
true
>>> print_r($c)
Array
(
[0] => 17
[1] => 234
[2] => 288
[3] => 324
[4] => 899
[5] => 900
[6] => 1212
[7] => 2323
)
>>> $a[]=199
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => $c=array_merge($a,$b)
[2] => sort($c,SORT_NUMERIC)
[1] => print_r($c)
[0] => $a[]=199
>>> h3
>>> $c=array_merge($a,$b)
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => sort($c,SORT_NUMERIC)
[2] => print_r($c)
[1] => $a[]=199
[0] => $c=array_merge($a,$b)
>>> h3
>>> sort($c,SORT_NUMERIC)
true
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => print_r($c)
[2] => $a[]=199
[1] => $c=array_merge($a,$b)
[0] => sort($c,SORT_NUMERIC)
>>> h3
>>> print_r($c)
Array
(
[0] => 17
[1] => 199
[2] => 234
[3] => 288
[4] => 324
[5] => 899
[6] => 900
[7] => 1212
[8] => 2323
)
>>>
Update:
Since PHP 5.1 there is (at last!) a built-in interactive mode as Johannes Schlüter shows in his blog, but this interactive mode needs readline support which isn’t part of the official Windows or Mac OS X builds. phpa-norl addresses anyone who doesn’t like to compile PHP.
Update:
Licence: phpa-norl is, like the original phpa, public domain. Feel free to do with it whatever you want.

Save This Page
[…] a patched version of the interactive command line PHP client, phpa to work on a Mac OS X machine - phpa-norl. phpa is an interactive command line shell for PHP by David Phillips. Stefan Fischerlander, […]
[…] Windows (the default builds theredo not seem to support a feature required by phpa). The result: phpa-norl. Stefan successfully ran this on OS X, and I could confirm that it runs on Windows, as […]
Works great under Win XP and Ubuntu Feisty, thanks a lot ! That’s what I was looking for since a long time cause it’s one of the features I miss from Python, and I can’t afford compiling php each time I need realines.
I espacially appreciate that you can forget the ‘”‘ and ‘;’ for quick test and directly print vars. What’s licence is it under ? Can I share it ? Modify it ? For now, I’ll just talk about it at my office.
Is there any place to report some bugs ? I’ll put the first one here :
Under Ubuntu 7.04, CTRL + D, which should semantically end the prompt, makes the script start an endless loop.
Still, it’s perfectly usable so no worries.
e-satis,
phpa-norl is public domain, so just use or modify it as you like. The original script phpa from David Phillips is also public domain.
I can confirm the CTRL-D bug is/was happening on Mac OS X too. I have now a patched version put online which should gracefully die if you press CTRL-D.
That what a quick fix. It’s clean on ubuntu too. Thanks again.
There seems to be a problem using the join() function, eg:
P:\>php phpa.php
PHP 5.2.5 (cli) (???) [WINNT]
>>> $j = join(”,”, array(”php”,”is”,”great”)
PHP Parse error: syntax error, unexpected ‘;’ in P:\phpa.php(66) : eval()’d code on line 1
false
>>>
Daniel,
there’s missing the closing parenthesis in your sample code.
This works for me:
>>> $j = join( “,”, array(”php “, “is “, “great “))
>>> $j
‘php ,is ,great ‘
>>>
Very useful information for me.
I know you’ve done some great work with ffmpeg - do you have any info about a utility that rearranges a Quicktime file to switch the moov atom to the front of the data, for streaming? (Tinic mentions qt-faststart.c?)
otogaz, I’ve never done anything with ffmpeg. Perhaps David has; he’s the author of the original phpa. The link to his site is in top part of my post.
phpa is an interactive command line shell for PHP and phpa can use either the CGI or CLI version of PHP. This shell works flawlessly under ubuntu. Thanks a lot.