<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Execute an external program and display raw output</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.exec.html">exec</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.proc-close.html">proc_close</a></div> <div class="up"><a href="ref.exec.html">Program execution Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.passthru" class="refentry"> <div class="refnamediv"> <h1 class="refname">passthru</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">passthru</span> — <span class="dc-title">Execute an external program and display raw output</span></p> </div> <div class="refsect1 description" id="refsect1-function.passthru-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>passthru</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$command</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$return_var</code></span> ] )</div> <p class="para rdfs-comment"> The <span class="function"><strong>passthru()</strong></span> function is similar to the <span class="function"><a href="function.exec.html" class="function">exec()</a></span> function in that it executes a <em><code class="parameter">command</code></em>. This function should be used in place of <span class="function"><a href="function.exec.html" class="function">exec()</a></span> or <span class="function"><a href="function.system.html" class="function">system()</a></span> when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly. By setting the Content-type to <em>image/gif</em> and then calling a pbmplus program to output a gif, you can create PHP scripts that output images directly. </p> </div> <div class="refsect1 parameters" id="refsect1-function.passthru-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">command</code></em></span> <dd> <p class="para"> The command that will be executed. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">return_var</code></em></span> <dd> <p class="para"> If the <em><code class="parameter">return_var</code></em> argument is present, the return status of the Unix command will be placed here. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.passthru-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 notes" id="refsect1-function.passthru-notes"> <h3 class="title">Notes</h3> <div class="warning"><strong class="warning">Warning</strong><p class="para">When allowing user-supplied data to be passed to this function, use <span class="function"><a href="function.escapeshellarg.html" class="function">escapeshellarg()</a></span> or <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> to ensure that users cannot trick the system into executing arbitrary commands.</p></div> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.</p></p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">When <a href="features.safe-mode.html" class="link">safe mode</a> is enabled, you can only execute files within the <a href="ini.sect.safe-mode.html#ini.safe-mode-exec-dir" class="link">safe_mode_exec_dir</a>. For practical reasons, it is currently not allowed to have <em>..</em> components in the path to the executable.</span></p></blockquote> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">With <a href="features.safe-mode.html" class="link">safe mode</a> enabled, the command string is escaped with <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span>. Thus, <em>echo y | echo x</em> becomes <em>echo y \| echo x</em>.</p></div> </div> <div class="refsect1 seealso" id="refsect1-function.passthru-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.exec.html" class="function" rel="rdfs-seeAlso">exec()</a> - Execute an external program</span></li> <li class="member"> <span class="function"><a href="function.system.html" class="function" rel="rdfs-seeAlso">system()</a> - Execute an external program and display the output</span></li> <li class="member"> <span class="function"><a href="function.popen.html" class="function" rel="rdfs-seeAlso">popen()</a> - Opens process file pointer</span></li> <li class="member"> <span class="function"><a href="function.escapeshellcmd.html" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - Escape shell metacharacters</span></li> <li class="member"><a href="language.operators.execution.html" class="link">backtick operator</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.exec.html">exec</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.proc-close.html">proc_close</a></div> <div class="up"><a href="ref.exec.html">Program execution Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>