Sunday, March 30, 2008

PHP Interactive Shell with one line of PHP

PHP lacks built in functionality for an interactive Shell such as built into Python, Perl etc. You can execute PHP from the shell using the php -r but it isn't interactive. Using php -a didn't work for me on both Win and Linux, so I wrote this single line PHP script that will allow an "interactive" PHP Shell.

#!/usr/bin/php
<?php while (1) {  fputs(STDOUT, "\n\-PHP$ "); eval(trim(fgets(STDIN))); } ?>
There it is on 1 line, plus the Shebang.

To use it just copy the code and save to a file. You don't need to give the file an extension. For example I named it iphp. Then you execute it in the shell using ./iphp. You should get $PHP as your prompt:
-bash-3.00$ ./iphp

$PHP

Now you type in your PHP commands such as:
-bash-3.00$ ./iphp

$PHP $result = 1+1;

$PHP echo $result;
2
$PHP
Notice how you can save a variable, and reference it later. This is the same for a mysql connection, file pointer etc.

When you're done, just type in exit;.

-bash-3.00$ ./iphp

$PHP $result = 1+1;

$PHP echo $result;
2
$PHP exit;
bash-3.00$

Update: April 16, 2008

In further tests:

php -a 
into the shell on Linux (Ubuntu 7.05) running PHP 5.2.4-2 (cli) works and takes you into interactive mode. I had previously tested this with PHP 5.1.6 (cli) on Linux (CentOS 3.9 and 4.6) and couldn't get it to work. The same with PHP4 and PHP5 (cli and module) on Windows.

Sunday, March 23, 2008

CMS: Joomla, Drupal, Wordpress Popularity and Activity

How popular is the Open Source CMS you use?

Due to many factors, we decided to use the Joomla CMS as our main Website Development Platform. This was more than 5 years ago. At the time, it was actually Mambo, or should I say MOS (Mambo Open Server).

I've always been interested in just how popular Joomla, and other major CMS and Blog software are. The results I found recently are quite interesting.

Joomla vs Drupal vs Wordpress Popularity Graphs

On Compete:

Wordpress gets close to 2.5 million visits per month compared to the 1 million for Drupal and Joomla as of March 2008.

As an open source developer, this is good to know. It is always good to develop open source software for the largest audience available. That way you get your software tested on a huge range of system and configuration, more feedback and generally more interest in your developments.

Sunday, March 16, 2008

Dict on Appjet

In a previous post I mentioned Appjet, a website service which allows you to create web apps with server side JavaScript. I visited the site today after quite a while and was suprised to see an example application I wrote as the most popular app on appjet. The application is called Dict