Home arrow PHP arrow Page 2 - PHP File and Operating System Program Execution Functions

More PHP Program Execution Functions - PHP

In this conclusion to an eight-part article series on working with a computer's file and operating system with PHP, you'll learn about the functions used in combination with a PHP script to execute system-level programs. This article is excerpted from chapter 10 of the book Beginning PHP and PostgreSQL 8: From Novice to Professional, written by W. Jason Gilmore and Robert H. Treat (Apress; ISBN: 1590595475).

TABLE OF CONTENTS:
  1. PHP File and Operating System Program Execution Functions
  2. More PHP Program Execution Functions
By: Apress Publishing
Rating: starstarstarstarstar / 0
January 03, 2012

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

passthru()

void passthru (string command [, int return_var])

The passthru() function is similar in function to exec(), except that it should be used if you'd like to return binary output to the caller. For example, suppose you want to convert GIF images to PNG before displaying them to the browser. You could use the Netpbm graphics package, available at http://netpbm.sourceforge.net/ under the GPL license:

<?php
header("ContentType:image/png");
passthru("giftopnm cover.gif | pnmtopng > cover.png");
?>

Backticks

Delimiting a string with backticks signals to PHP that the string should be executed as a shell command, returning any output. Note that backticks are not single quotes, but rather are a slanted cousin, commonly sharing a key with the tilde (~) on most American keyboards. An example follows:

<?php
$result = `date`;
echo "<p>The server timestamp is: $result</p>";
?>

This returns something similar to:

--------------------------------------------The server timestamp is: Sun Jun 15 15:32:14 EDT 2003
--------------------------------------------

The backtick operator is operationally identical to the shellexec() function, introduced next.

shell_exec()

string shell_exec (string command)

The shell_exec() function offers a syntactical alternative to backticks, executing a shell command and returning the output. Reconsidering the preceding example:

<?php
$result = shell_exec("date");
echo "<p>The server timestamp is: $result</p>";
?>

Summary

Although you can certainly go a very long way using solely PHP to build interesting and powerful Web applications, such capabilities are greatly expanded when functionality is integrated with the underlying platform and other technologies. As applied to this chapter, these technologies include the underlying operating and file systems. You'll see this theme repeatedly throughout the remainder of this book, as PHPs ability to interface with a wide variety of technologies like LDAP, SOAP, and Web Services is introduced.

In the next chapter, you'll examine two key aspects of any Web application: Web forms and navigational cues.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: