Section 11.4. Calling System Calls


11.4. Calling System Calls

A system call is used by an application to request service from the operating system. System calls use machine code instructions, which causes the processor to change modes. Changing the mode gets the OS to perform restricted actions; for example, accessing hardware devices or server space available.

Every OS provides a library that sits between normal programs and the rest of the operating system, such as the Windows API. This library handles low-level details of passing information to the kernel and switching to supervisor mode.

You can use the exec function to call external functions.

For maximum security, use exec only when PHP code doesn't provide the same functionality.


For example, if you'd like to get information about how much space is available on the server, execute the df command, shown in Example 11-29. However, this is assuming you're on a Unix host.

Example 11-29. Executing df and displaying the results

 <?php exec("df",$output_lines,$return_value); echo ("Command returned a value of $return_value."); echo "</pre>"; foreach ($output_lines as $output) {   echo "$o"; } echo "</pre>"; ?> 

For our system, we get the screen in Figure 11-23.

Figure 11-23. A synopsis of how full the hard disk is, from PHP


Use extreme caution! Remember that while linking other commands in this chapter, you should avoid passing user input to exec because there's a substantial risk for misuse.


We're now going to discuss modifying objects in MySQL and working with data using PHP.



Learning PHP and MySQL
Learning PHP and MySQL
ISBN: 0596101104
EAN: 2147483647
Year: N/A
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net