PHP Notes

Table of Contents

Things to look at

Books to read

Magazines/Publications & Groups

Saving a file



SOAP calls and debug

$client = new SoapClient($WebSvcWSDL,array(	'login'     => $login,
						'password'  => $password,
						'location'  => $WebSvcURL,
						'trace'     => 1,
						'exceptions' => 0));
//trace allows getLastRequest and getLastResponse to be called 
//- these show the SOAP XML send and recieved
//exceptions stops the SoapClient calls from throwing exceptions

$result = $client->commandfromWebSvcWSDL(array('thecommand' => $command));

print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>\n";

SOAP Exceptions

    $client = new SoapClient($WebSvcWSDL,array(	'login'     => $login,
						'password'  => $password,
						'location'  => $WebSvcURL));
    $result = $client->commandfromWebSvcWSDL(array('thecommand' => $command));
catch (SoapFault $e)
    echo("\n<br />Error making SOAP call<br />\n");
    echo $e->getMessage();
    echo $e->faultcode;
    echo $e->faultstring;



taken from Cisco CUCM AXL (SOAP) interface example in the Cisco Developer Network Administration XML page

  <title>PHP Test</title>
 $client = new SoapClient("/var/www/AXLAPI.wsdl",
 $response = $client->getUser(array("userid"=>"jsmith"));
 echo("First Name: ".$response->return->user->firstname)."<br>";
 echo("Last Name: ".$response->return->user->lastname);

SOAP References

Quick tutorial on PHP SOAP extension
Dr. Herong Yang's PHP SOAP Extension Tutorial
SOAP commands
Cisco CUCM AXL (SOAP) interface example


PHP Expect - expect_expectl

Splitting multiline text box into array

Taken from
$text = $_POST['userlist'];
$array = explode('\n', $text);

Flushing HTML output


PECL extensions

Using an extension

in your php.ini, put a line
  extension = dir/
Check to make sure it loaded using the phpinfo() call.

Alternatively, load in php script using

Building AJAX Applications with PHP and HTML_AJAX

PHP and named pipes

Lifted Scripts


taken from Matthew Weier O'Phinney's Weblog
    *  To display errors:
          o In you php.ini file, set "display_errors = On", or
          o In your script, add the line "ini_set('display_errors', true);"
    * To show notices, warnings, errors, deprecation notices:
          o In you php.ini file, set "error_reporting = E_ALL | E_STRICT", or
          o In your script, add the line "error_reporting(E_ALL | E_STRICT);"

Alternatively, you can create a file with the lines:

    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', true);

and then set the php.ini setting 'auto_prepend_file' to the path to that file.

NOTE: do not do any of the above on a production system! PHP's error messages often reveal a lot about your applications, including file layout and potential vectors of attack. Turn display_errors off on production machines, set your error_reporting somewhat lower, and log_errors to a file so you can keep track of what's going on on your production system.

The second part of the question was how to run a PHP script on the command line. This is incredibly simple: php myscript.php. No different than any other scripting language.

You can get some good information by using some of the switches, though. '-l' turns the PHP interpreter into a linter, and can let you know if your code is well-formed (which doesn't necessarily preclude runtime or parse errors). '-f' will run the script through the parser, which can give you even more information. I typically bind these actions to keys in vim so I can check my work as I go.

If you plan on running your code solely on the commandline, add a shebang to the first line of your script: #!/path/to/php. Then make the script executable, and you're good to go. This is handy for cronjobs, or batch processing scripts.

All of this information is readily available in the PHP manual, and the commandline options are always available by passing the --help switch to the PHP executable. So, start testing your scripts already!

Running PHP from the command line

php -f <php script>
php -f hello-world.php