diff --git a/pipi-php/examples/histogram.php b/pipi-php/examples/histogram.php
index 0685217..5bbfffe 100644
--- a/pipi-php/examples/histogram.php
+++ b/pipi-php/examples/histogram.php
@@ -5,7 +5,7 @@ $img = pipi_contrast($img, 0.98);
 
 $histogram = pipi_new_histogram();
 $histogram_img = pipi_new(320, 200);
-echo pipi_get_image_histogram($img, $histogram, 1);
-echo pipi_render_histogram($img_histogram, $histogram, 1);
+pipi_get_image_histogram($img, $histogram, 1);
+pipi_render_histogram($img_histogram, $histogram, 1);
 
 pipi_save($histogram_img, "out.png");
diff --git a/pipi-php/examples/pipi.php b/pipi-php/examples/pipi.php
new file mode 100755
index 0000000..8af606f
--- /dev/null
+++ b/pipi-php/examples/pipi.php
@@ -0,0 +1,48 @@
+#!/usr/bin/php5
+<?
+$aliases = array(
+	"-o" => "--save", 
+	"--output" => "--save"
+);
+
+$ctx = pipi_create_context();
+$list = pipi_get_command_list();
+
+for ($argi = 1; $argi < $argc; $argi++) {
+
+	$arg = $argv[$argi];
+	if (isset($aliases[$arg]))
+		$arg = $aliases[$arg];
+
+	if (substr($arg, 0, 2) == "--")	{
+		$cmd_name = substr($arg, 2);
+
+		if (!isset($list[$cmd_name])) {
+			die("unknown command $cmd_name\n");
+		}
+		
+		$cmd_argc = $list[$cmd_name];
+	        if ($argi + $cmd_argc > $argc) {
+			die("too few arguments for $arg_name\n");
+	        }
+
+		switch ($cmd_argc) {
+			case 0:	
+				$res = pipi_command($ctx, $cmd_name);
+				break;
+			case 1:
+				$res = pipi_command($ctx, $cmd_name, $argv[$argi + 1]);
+				break;
+			default:
+				die();
+		}
+		if ($res != 0) {
+			die("command $cmd_name failed\n");
+		}
+		$argi += $cmd_argc;
+	}
+	else {
+		  if (pipi_command($ctx, "load", $arg) != 0)
+			die("could not load $arg\n");
+	}
+}
diff --git a/pipi-php/php_pipi.c b/pipi-php/php_pipi.c
index 1da04ff..ac8abd6 100644
--- a/pipi-php/php_pipi.c
+++ b/pipi-php/php_pipi.c
@@ -202,6 +202,20 @@ PHP_FUNCTION(pipi_get_command_list) {
 }
 
 PHP_FUNCTION(pipi_command) {
+	zval *res;
+	char *arg1, *arg2 = NULL;
+	int arg1_len, arg2_len;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &arg1, &arg1_len, &arg2, &arg2_len) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	pipi_context_t *ctxt;
+	ZEND_FETCH_RESOURCE(ctxt, pipi_context_t*, &res, -1, PHP_PIPI_CONTEXT_RES_NAME, le_pipi_context); 
+
+	if (arg2_len != 0) {
+		RETURN_LONG(pipi_command(ctxt, arg1, arg2));
+	}
+	RETURN_LONG(pipi_command(ctxt, arg1));	
 }
 
 PHP_FUNCTION(pipi_load) {