systemNamesystem — Executes command cmd in the system's command interpreter and returns the last line of output. An optional argument allows the return value to be captured.Descriptionsystem() attempts to execute cmd in the system's command interpreter. PHP waits until the command interpreter returns before execution of the script continues past the call to system() . Output from the command is sent directly to stdout. If the return_value argument is set, the return value of the command is stored in this variable. ExampleExample 1099. Use passthru() to display recent errors from the Apache error log for a specific user <pre> <?php // this script is for UNIX-like operating systems // Set the location to an apache error log $error_log = '/var/www/logs/error_log'; // Find who the owner of this script is // Find out the owner's username, home directory, and other details $user = posix_getpwuid (fileowner ($SCRIPT_FILENAME)); /* Use shell commands to parse an apache error_log for entries that have the user's home directory in them For more information on tail and grep, see your system man pages */ passthru ("tail -n 1000 $error_log | grep $user[dir]"); ?> </pre> Example 1100. Display all entries for a specific directory from the current IIS log file <pre> <?php // This script is for NT and Windows 2000 Professional/Server products only /* Set the term to search for. In this case, we're looking for the root directory 'bugs' Note the double quotes inside the single quotes. Find requires that the search term be quoted by double quotes. */ $search_term = '" /bugs/"'; // Create a name for the current date's log file $log_file_name = 'EX' . gmdate ('ymd') . '.log'; // Use the Find command to search through the log file for $search_term system ("find $search_term %WinDir%\\System32\\LogFiles\\W3SVC1\\$log_file_name"); ?> </pre>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|