cvs: phpdoc /kr/features connection-handling.xml cookies.xml error-handling.xml file-upload.xml http-auth.xml images.xml persistent-connections.xml
remote-files.xml
| From: | Damien Seguy | Date: | Tue, 09 Jan 2001 10:58:55 +0000 |
| Subject: | cvs: phpdoc /kr/features connection-handling.xml cookies.xml error-handling.xml file-upload.xml http-auth.xml images.xml persistent-connections.xml remote-files.xml |
||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969333504@lists.php.net to get a copy of this message | ||
dams Tue Jan 9 02:58:55 2001 EDT
Added files:
/phpdoc/kr/features cookies.xml error-handling.xml file-upload.xml
http-auth.xml images.xml
persistent-connections.xml remote-files.xml
connection-handling.xml
Log:
Added original English version
Index: phpdoc/kr/features/cookies.xml +++ phpdoc/kr/features/cookies.xml <chapter id="features.cookies"> <title>Cookies</title> <para> PHPÎäî HTTP Cookieκ Ìà¨ÎÖÌïò;å(transparently) ÏßÄÏõêÌïúÎã§. Cookie Ωîϼ¥Îãà϶òÏùÄ Ìä½ÎûòÌǼÏù¥ÎÇò ÏǨÏö©Ïûê ÏãùÎÑ Îì±ÏùÑ ÏúÑÌï¥ Ïõê;© browserÏóê ÏÝÄÏûÎêú ÎçÏù¥ÌÑκ ÎèåÎݧ ÎõÎäî ͺÏÝïÏùÑ ÎßêÌïúÎã§. Ïó¨Îü¨ÎÑÏùÄ cookieκ ÏѧÏÝïÌïòͽ ÏúÑÌï¥ <function>setcookie</function> Ìï®Ïàòκ ÏǨÏö©ÌïÝ Ïàò ÏûàÎã§. CookieÎäî HTTP Ìó§ÎçîÏùò Ìïú ÎÄÎÑÏù¥ÎØÄΰú, <function>setcookie</function> Ìï®ÏàòÎäî νåÎùºÏöÏÝÄΰú Î¥ÎÇ¥Îäî Ïñ¥Îñ§ ÎçÏù¥ÌÑÎ¥Îã§ÎèÑ ÏïûÏóê ÏǨÏö©Ìï¥Ïïº ÌïúÎã§. Ïù¥ ÏÝúÏïÏùÄ <function>header</function> Ìï®ÏàòÏôÄ ÍôÏùÄ ÏÝúÏïÏúºÎ°ú ΥΩ¥ ÎêúÎã§.</para> <para> ÌÅ¥ÎùºÏù¥Ïñ½Ìä½ÍÄ Î¥ÎÇ¥Ï§Ä Î®ÎìÝ cookieÎäî ÏûêÎèôÏÝÅÏúºÎ°ú GETÏù¥ÎÇò POST ΩÏãù ÎçÏù¥ÌÑÏôÄ ÍôÏùÄ PHP ÎÄÏàòΰú ÎÄÌôòÎêúÎã§. ÎßåÏï Ïó¨Îü¨ÎÑÏù¥ ÎèôÏùºÌïú cookieÏóê Ïó¨Îü¨ ÍíÏùÑ ÏÝÄÏûÌïòÍÝ ÏãÎã§Î©¥ CookieÏù¥Î¶ÑÏóê <emphasis>[]</emphasis>κ ÎçîÌïòΩ¥ ÎêúÎã§. ÏûêÏѽÌïú ;ÉÏùÄ <function>setcookie</function> Ìï®Ïàò ÏѧÎÖÏùÑ Ï½Ï°ÌïòÏûê. </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/error-handling.xml +++ phpdoc/kr/features/error-handling.xml <chapter id="features.error-handling"> <title>Error Handling</title> <para> PHPÏóêÎäî Îã§Ïùåͺ ÍôÏùÄ Ïó¨Îü¨ ÏóêÎü¨ÏôÄ Í¾ÍÝ ÌòïÌÉúÍÄ ÏûàÎã§.: <table> <title>PHP error types</title> <tgroup cols="4"> <thead> <row> <entry>Value</entry> <entry>Constant</entry> <entry>Description</entry> <entry>Note</entry> </row> </thead> <tbody> <row> <entry>1</entry> <entry>E_ERROR</entry> <entry>Normal Function Errors (ÏùºÎòÏÝÅÏù½ ÏóêÎü¨)</entry> <entry/> </row> <row> <entry>2</entry> <entry>E_WARNING</entry> <entry>Normal Warnings (ÏùºÎòÏÝÅÏù½ ;ÍÝ)</entry> <entry/> </row> <row> <entry>4</entry> <entry>E_PARSE</entry> <entry>Parser Errors (Ψ½Î¾ï ÏóêÎü¨)</entry> <entry/> </row> <row> <entry>8</entry> <entry>E_NOTICE </entry> <entry> Notices (Ψ¥ÏãúÌïÝ Ïàò ÏûàÎäî ÏïåζºÏù¥ÏßÄÎßå ξÑÍ ½Ïùò ÍÄÎäÏѱÏùÑ ÍÄÏßÄÍÝ ÏûàÎäî ;Ïö) </entry> <entry/> </row> <row> <entry>16</entry> <entry>E_CORE_ERROR</entry> <entry>fatal errors that occur during PHP's initial startup (PHPÍÄ Ï¾òÏùå ÏãúÏûëÎêÝ Îïå ÎúÏÉùÌïú ϼòÎÖÏÝÅ ÏóêÎü¨)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>32</entry> <entry>E_CORE_WARNING</entry> <entry>warnings (non fatal errors) that occur during PHP's initial startup (PHPÍÄ Ï¾òÏùå ÏãúÏûëÎêÝ Îïå ÎúÏÉùÌïú ϼòÎÖÏÝÅÏù¥ÏßÄ ÏïäÏùÄ Í¾ÍÝ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>64</entry> <entry>E_COMPILE_ERROR</entry> <entry>fatal compile-time errors (Ϫ¥ÌååÏùºÏãú ÏÉùͽ¥ ϼòÎÖÏÝÅ ÏóêÎü¨)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>128</entry> <entry>E_COMPILE_WARNING</entry> <entry>compile-time warnings (non fatal errors) (Ϫ¥ÌååÏùºÏãú ÎúÏÉùÌïú ϼòÎÖÏÝÅÏù¥ÏßÄ ÏïäÏùÄ Í¾ÍÝ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>256</entry> <entry>E_USER_ERROR</entry> <entry>user-generated error message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ ÏóêÎü¨ ΩîÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>512</entry> <entry>E_USER_WARNING</entry> <entry>user-generated warning message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ Í¾ÍÝ Î©îÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>1024</entry> <entry>E_USER_NOTICE </entry> <entry>user-generated notice message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ Ïïåζº ΩîÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry/> <entry>E_ALL</entry> <entry>all of the above, as supported (ÏßÄÏõêÍÄÎäÌïú ÏúÑÏùò Í¾É Î®Îëê)</entry> <entry/> </row> </tbody> </tgroup> </table> </para> <para> The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the <link linkend="language.operators.bitwise">bitwise operators</link> to combine these values or mask out certain types of errors. Note that only '|', '~', '!', and '&' will be understood within <filename>php.ini</filename>, however, and that no bitwise operators will be understood within <filename>php3.ini</filename>. </para> <para> In PHP 4, the default <link linkend="ini.error-reporting">error_reporting</link> setting is <literal>E_ALL & ~E_NOTICE</literal>, meaning to display all errors and warnings which are not E_NOTICE-level. In PHP 3, the default setting is <literal>(E_ERROR | E_WARNING | E_PARSE)</literal>, meaning the same thing. Note, however, that since constants are not supported in PHP 3's <filename>php3.ini</filename>, the <link linkend="ini.error-reporting">error_reporting</link> setting there must be numeric; hence, it is <literal>7</literal>. </para> <para> The initial setting can be changed in the ini file with the <link linkend="ini.error-reporting">error_reporting</link> directive, in your Apache <filename>httpd.conf</filename> file with the php_error_reporting (php3_error_reporting for PHP 3) directive, and lastly it may be set at runtime within a script by using the <function>error_reporting</function> function. </para> <warning> <para> When upgrading code or servers from PHP 3 to PHP 4 you should check these settings and calls to <function>error_reporting</function> or you might disable reporting the new error types, especially E_COMPILE_ERROR. This may lead to empty documents without any feedback of what happened or where to look for the problem. </para> </warning> <para> ήÎìÝ <link linkend="language.expressions">PHP ÌëúÌòÑÏãù(expression)</link>ÏùÄ "@"κ ÏïûÏóê ÎôÏù¥ÍÝ Ìò½ÏúÎêòΩ¥ error reportingÏùÑ ÌïòÏßÄ ÏïäÎäîÎã§. ÎßåÏï <link linkend="ini.track-errors">track_errors</link> ÏòµÏÖòÏù¥ Enabledΰú ÎêòÏñ¥ ÏûàÍÝ Ìï¥Î㼠Ψ½ÏûÏóêÏÑú ÏóêÎü¨ÍÄ ÎúÏÉùÌñàÎã§Î©¥, $php_errormsgÎùºÎäî ÏÝÑÏóÎÄÏàòÏóê ÏóêÎü¨ ΩîÏãúÏßÄÍÄ Îã¥Í¾® Ïûà;å ÎêúÎã§. </para> <warning> <para> Currently the <link linkend="language.operators.errorcontrol">@ error-control operator</link> prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use <link linkend="language.operators.errorcontrol">@</link> to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. </para> </warning> <para> Below we can see an example of using the error handling capabilities in PHP. We define a error handling function which logs the information into a file (using an XML format), and e-mails the developer in case a critical error in the logic happens. <example> <title>Using error handling in a script</title> <programlisting role="php"> <?php // we will do our own error handling error_reporting(0); // user defined error handling function function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) { // timestamp for the error entry $dt = date("Y-m-d H:i:s (T)"); // define an assoc array of error string // in reality the only entries we should // consider are 2,8,256,512 and 1024 $errortype = array ( 1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024=> "User Notice" ); // set of errors for which a var trace will be saved $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "<errorentry>\n"; $err .= "\t<datetime>".$dt."</datetime>\n"; $err .= "\t<errornum>".$errno."</errnumber>\n"; $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n"; $err .= "\t<errormsg>".$errmsg."</errormsg>\n"; $err .= "\t<scriptname>".$filename."</scriptname>\n"; $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n"; if (in_array($errno, $user_errors)) $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n"; $err .= "</errorentry>\n\n"; // for testing // echo $err; // save to the error log, and e-mail me if there is a critical user error error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) mail("phpdev@mydomain.com","Critical User Error",$err); } function distance ($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } $d += $c2*$c2 - $c1*$c1; } return sqrt($d); } $old_error_handler = set_error_handler("userErrorHandler"); // undefined constant, generates a warning $t = I_AM_NOT_DEFINED; // define some "vectors" $a = array(2,3,"foo"); $b = array(5.5, 4.3, -1.6); $c = array (1,-3); // generate a user error $t1 = distance($c,$b)."\n"; // generate another user error $t2 = distance($b,"i am not an array")."\n"; // generate a warning $t3 = distance($a,$b)."\n"; ?> </programlisting> </example> This is just a simple example showing how to use the <link linkend="ref.errorfunc">Error Handling and Logging functions</link>. </para> <para> See also <function>error_reporting</function>, <function>error_log</function>, <function>set_error_handler</function>, <function>restore_error_handler</function>, <function>trigger_error</function>, <function>user_error</function> </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/file-upload.xml +++ phpdoc/kr/features/file-upload.xml <chapter id="features.file-upload"> <title>Handling file uploads</title> <sect1 id="features.file-upload.post-method"> <title>POST method uploads</title> <simpara> PHP is capable of receiving file uploads from any RFC-1867 compliant browser (which includes Netscape Navigator 3 or later, Microsoft Internet Explorer 3 with a patch from Microsoft, or later without a patch). This feature lets people upload both text and binary files. With PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded. </simpara> <para> Note that PHP also supports PUT-method file uploads as used by Netscape Composer and W3C's Amaya clients. See the <link linkend="features.file-upload.put-method">PUT Method Support</link> for more details. </para> <para> A file upload screen can be built by creating a special form which looks something like this: <example> <title>File Upload Form</title> <programlisting> <FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000"> Send this file: <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" VALUE="Send File"> </FORM> </programlisting> </example> The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden field must precede the file input field and its value is the maximum filesize accepted. The value is in bytes. </para> <para> In PHP 3, the following variables will be defined within the destination script upon a successful upload, assuming that <link linkend="ini.register-globals">register_globals</link> is turned on in <filename>php3.ini</filename>. If <link linkend="ini.track-vars">track_vars</link> is turned on, they will also be available in PHP 3 within the global array <varname>$HTTP_POST_VARS</varname>. Note that the following variable names assume the use of the file upload name 'userfile', as used in the example above: <itemizedlist> <listitem> <simpara> <varname>$userfile</varname> - The temporary filename in which the uploaded file was stored on the server machine. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_name</varname> - The original name or path of the file on the sender's system. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_size</varname> - The size of the uploaded file in bytes. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_type</varname> - The mime type of the file if the browser provided this information. An example would be "image/gif". </simpara> </listitem> </itemizedlist> Note that the "$userfile" part of the above variables is whatever the name of the INPUT field of TYPE=file is in the upload form. In the above upload form example, we chose to call it "userfile" </para> <para> In PHP 4, the behaviour is slightly different, in that the new global array <varname>$HTTP_POST_FILES</varname> is provided to contain the uploaded file information. This is still only available if <link linkend="ini.track-vars">track_vars</link> is turned on, but <link linkend="ini.track-vars">track_vars</link> is always turned on in versions of PHP after PHP 4.0.2. </para> <para> The contents of <varname>$HTTP_POST_FILES</varname> are as follows. Note that this assumes the use of the file upload name 'userfile', as used in the example above: <variablelist> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['name']</varname></term> <listitem> <para> The original name of the file on the client machine. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['type']</varname></term> <listitem> <para> The mime type of the file, if the browser provided this information. An example would be <literal>"image/gif"</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['size']</varname></term> <listitem> <para> The size, in bytes, of the uploaded file. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['tmp_name']</varname></term> <listitem> <para> The temporary filename of the file in which the uploaded file was stored on the server. </para> </listitem> </varlistentry> </variablelist> </para> <para> Files will by default be stored in the server's default temporary directory, unless another location has been given with the <link linkend="ini.upload-tmp-dir">upload_tmp_dir</link> directive in <filename>php.ini</filename>. The server's default directory can be changed by setting the environment variable <envar>TMPDIR</envar> in the environment in which PHP runs. Setting it using <function>putenv</function> from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well. <example> <title>Validating file uploads</title> <para> The following examples are for versions of PHP 3 greater than 3.0.16, and versions of PHP 4 greater than 4.0.2. See the function entries for <function>is_uploaded_file</function> and <function>move_uploaded_file</function>. </para> <programlisting role="php"> <?php if (is_uploaded_file($userfile)) { copy($userfile, "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack: filename '$userfile'."; } /* ...or... */ move_uploaded_file($userfile, "/place/to/put/uploaded/file"); ?> </programlisting> <para> For earlier versions of PHP, you'll need to do something like the following. <note> <para> This will <emphasis>not</emphasis> work in versions of PHP 4 after 4.0.2. It depends on internal functionality of PHP which changed after that version. </para> </note> </para> <programlisting role="php"> <?php /* Userland test for uploaded file. */ function is_uploaded_file($filename) { if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { $tmp_file = dirname(tempnam('', '')); } $tmp_file .= '/' . basename($filename); /* User might have trailing slash in php.ini... */ return (ereg_replace('/+', '/', $tmp_file) == $filename); } if (is_uploaded_file($userfile)) { copy($userfile, "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack: filename '$userfile'."; } ?> </programlisting> </example> </para> <simpara> The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can for example use the <varname>$file_size</varname> variable to throw away any files that are either too small or too big. You could use the <varname>$file_type</varname> variable to throw away any files that didn't match a certain type criteria. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere. </simpara> <simpara> The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed. </simpara> </sect1> <sect1 id="features.file-upload.common-pitfalls"> <title>Common Pitfalls</title> <simpara> The MAX_FILE_SIZE item cannot specify a file size greater than the file size that has been set in the upload_max_filesize in the PHP 3.ini file or the corresponding php3_upload_max_filesize Apache .conf directive. The default is 2 Megabytes. </simpara> <simpara> Not validating which file you operate on may mean that users can access sensitive information in other directories. </simpara> <simpara> Please note that the CERN httpd seems to strip off everything starting at the first whitespace in the content-type mime header it gets from the client. As long as this is the case, CERN httpd will not support the file upload feature. </simpara> </sect1> <sect1 id="feature-fileupload.multiple"> <title>Uploading multiple files</title> <simpara> It is possible to upload multiple files simultaneously and have the information organized automatically in arrays for you. To do so, you need to use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes: </simpara> <note> <para> Support for multiple file uploads was added in version 3.0.10. </para> </note> <para> <example> <title>Uploading multiple files</title> <programlisting> <form action="file-upload.php" method="post" enctype="multipart/form-data"> Send these files:<br> <input name="userfile[]" type="file"><br> <input name="userfile[]" type="file"><br> <input type="submit" value="Send files"> </form> </programlisting> </example> </para> <simpara> When the above form is submitted, the arrays <computeroutput>$userfile</computeroutput>, <computeroutput>$userfile_name</computeroutput>, and <computeroutput>$userfile_size</computeroutput> will be formed in the global scope (as well as in $HTTP_POST_FILES ($HTTP_POST_VARS in PHP 3)). Each of these will be a numerically indexed array of the appropriate values for the submitted files. </simpara> <simpara> For instance, assume that the filenames <filename>/home/test/review.html</filename> and <filename>/home/test/xwp.out</filename> are submitted. In this case, <computeroutput>$userfile_name[0]</computeroutput> would contain the value <computeroutput>review.html</computeroutput>, and <computeroutput>$userfile_name[1]</computeroutput> would contain the value <computeroutput>xwp.out</computeroutput>. Similarly, <computeroutput>$userfile_size[0]</computeroutput> would contain <filename>review.html</filename>'s filesize, and so forth. </simpara> <simpara> <computeroutput>$userfile['name'][0]</computeroutput>, <computeroutput>$userfile['tmp_name'][0]</computeroutput>, <computeroutput>$userfile['size'][0]</computeroutput>, and <computeroutput>$userfile['type'][0]</computeroutput> are also set. </simpara> </sect1> <sect1 id="features.file-upload.put-method"> <title>PUT method support</title> <para> PHP provides support for the HTTP PUT method used by clients such as Netscape Composer and W3C Amaya. PUT requests are much simpler than a file upload and they look something like this: <informalexample> <programlisting> PUT /path/filename.html HTTP/1.1 </programlisting> </informalexample> </para> <para> This would normally mean that the remote client would like to save the content that follows as: /path/filename.html in your web tree. It is obviously not a good idea for Apache or PHP to automatically let everybody overwrite any files in your web tree. So, to handle such a request you have to first tell your web server that you want a certain PHP script to handle the request. In Apache you do this with the <emphasis>Script</emphasis> directive. It can be placed almost anywhere in your Apache configuration file. A common place is inside a <Directory> block or perhaps inside a <Virtualhost> block. A line like this would do the trick: <informalexample> <programlisting> Script PUT /put.php3 </programlisting> </informalexample> </para> <simpara> This tells Apache to send all PUT requests for URIs that match the context in which you put this line to the put.php3 script. This assumes, of course, that you have PHP enabled for the .php3 extension and PHP is active. </simpara> <simpara> Inside your put.php3 file you would then do something like this: </simpara> <para> <informalexample><programlisting> <?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?> </programlisting></informalexample> </para> <simpara> This would copy the file to the location requested by the remote client. You would probably want to perform some checks and/or authenticate the user before performing this file copy. The only trick here is that when PHP sees a PUT-method request it stores the uploaded file in a temporary file just like those handled but the <link linkend="features.file-upload.post-method">POST-method</link>. When the request ends, this temporary file is deleted. So, your PUT handling PHP script has to copy that file somewhere. The filename of this temporary file is in the $PHP_PUT_FILENAME variable, and you can see the suggested destination filename in the $REQUEST_URI (may vary on non-Apache web servers). This destination filename is the one that the remote client specified. You do not have to listen to this client. You could, for example, copy all uploaded files to a special uploads directory. </simpara> </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/http-auth.xml +++ phpdoc/kr/features/http-auth.xml <chapter id="features.http-auth"> <title>HTTP authentication with PHP</title> <simpara> (ÏóÏûêÏ£º. HTTP authenticationÏù¥ÎûÄ Web ClientÏóê;å IDÏôÄ Passwordκ ÏûÖÎÝÎõÏïÑ, Í ½ IDÏôÄ Passwordΰú WebΨ½ÏÑúÏóê ÏÝëÍ ºÏùÑ ÌóàÍÄ, ÎàÌóàÌïòÎäî ͽÎäÏùÑ ÎßêÌïúÎã§. ÏûêÏѽÌûà ÏïåÍÝ ÏãÎã§Î©¥ RFC1945Ïùò Authentication ÎÄÎÑÏùÑ Ï½ÍÝÌïòͽ ÎîÎûÄÎã§. http://pec.etri.re.kr/!qkim/HTTP/Ïóê ÌïúÍ½Ä Î¾àÏó Ψ½ÏÑúÎèÑ ÏûàÏúºÎãà ϽϰÌïòÏûê.) </simpara> <simpara> PHPκ ÏǨÏö©Ìïú HTTP Ïù½Ï¶ùÏùÄ Apache ήÎìàΰú ÏǨÏö©ÎêÝ ÎïåÎßå ÎèôÏûëÌïúÎã§. CGI ξÑÏݺÏóêÏÑúÎäî Ïù¥ ͽÎäÏùÑ ÏǨÏö©ÌïÝ Ïàò ÏóÜÎã§. Apache ήÎìàÏùò PHP Ïä§ÌŨζÌä½ÏóêÏÑú <function>Header</function>ÎùºÎäî Ìï®Ïàòκ ÏǨÏö©ÌïòΩ¥ Client νåÎùºÏöÏÝÄÏóê;å Usernameͺ Passwordκ ÏûÖÎÝÎõÎäî ÏúàÎèÑÏöκ ÎùÑÏöÎèÑΰù ÌïòÎäî "Ïù½Ï¶ù Ïöî͵¨"("Authentication Required") ΩîÏãúÏßÄκ Î¥ÎǺ Ïàò ÏûàÎã§. ÏùºÎã® ÏǨÏö©ÏûêÍÄ Usernameͺ Passwordκ ÏûÖÎÝÌïòΩ¥, user name, password, authentication typeÏùò ÍíÏùÑ ÍÄÏßÄÎäî $PHP_AUTH_USER, $PHP_AUTH_PW, $PHP_AUTH_TYPEÏùò 3ÍúÏùò ÎÄÏàòκ ÍÄÏßÄÍÝ Ìï¥Îã¼ URL(PHP Ïä§ÌŨζÌä½Îº Ìè¨Ìï®Ìïú)Ïù¥ Îã§Ïãú Îàζ¨ÏõåÏßÑÎã§. ÌòÑÏû¨ authentication typeÏùÄ "Basic"ÎßåÏù¥ ÏßÄÏõêÎêúÎã§. ÏûêÏѽÌïú ÏǨÏö©Î¾ïÏùÄ <function>Header</function> Ìï®Ïàòκ ÏÇ¥Ìé¥ Î¥Ïûê.</simpara> <para> client authenticationÏùÑ ÏǨÏö©ÌïòÏó¨ Í ½ ÏûÖÎÝÎêú ÍíÏùÑ ÏúÎÝÌïòÎäî ÏòàÏÝúÍÄ ÏïÑÎûòÏóê ÏûàÎã§. : <example> <title>HTTP Authentication example</title> <programlisting role="php"> <?php if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic realm=\"My Realm\""); Header("HTTP/1.0 401 Unauthorized"); echo "Text to send if user hits Cancel button\n"; exit; } else { echo "Hello $PHP_AUTH_USER.<P>"; echo "You entered $PHP_AUTH_PW as your password.<P>"; } ?> </programlisting> </example> </para> <para> Ïó¨Îü¨ÎÑÏùÄ $PHP_AUTH_USER ÏôÄ $PHP_AUTH_PWκ Îã®ÏàúÌûà ÏúÎÝÌïòÎäî ÎåÄÏãÝ, ÏǨÏö©ÏûêÏùò ÏãùÎÑÏùÑ ÏúÑÌï¥ usernameͺ passwordκ ÏǨÏö©Ìïòͽκ ÏõêÌïÝ Í¾ÉÏù¥Îã§. Ïù¥ÎïåÎäî DatabaseÏóê QueryÌïòͱÎÇò ÏßÅÏÝë dbm ÌååÏùºÏóêÏÑú ÏæÏïÑÎ¥Îäî Îì±Ïùò ΩξïÏúºÎ°ú ÍÄÎäÌïÝ Í¾ÉÏù¥Îã§.</para> <para> Internet Explorer browserÏóêÏÑúÎäî ξÑÍ ½Î°ú Ïù½Ìï¥ HeaderÏùò ÏàúÏÑúÍÄ Îß§Ïö ͼåÎã§Î°Îã§. <emphasis>WWW-Authenticate</emphasis>κ <errorcode>HTTP/1.0 401</errorcode>Î¥Î㧠ήºÏÝÄ Î¥ÎÇ¥Îäî ;ÉÏù¥ ÌòÑÏû¨ ÍÄÎäÌïú Ìä½Î¶ÏúºÎ°ú Î¥Ïù½Îã§. </para> <simpara> μÑÎÄξàÌò½Ïùò ÏúÝÏúÏùÑ ÏöÎݧÌïòÏó¨ HTTPÏóêÏÑú ÏÝú͵ÌïòÎäî Ïù½Ï¶ùÏùÑ ÏǨÏö©ÌïòÎäî ÎåÄÏãÝ Í½Ï°¥Ïùò Ïô½ÎÄ Î©îϼ¥Îãà϶òÏùÑ ÏǨÏö©ÌïÝ Í¾ÏöÏóêÎäî ΨºÎ°Ý PHP_AUTH ÎÄÏàòÎäî ÏѧÏÝïÎêòÏßÄ ÏïäÎäîÎã§. Ïù¥Îü;Ïö externally-authenticated userκ ÌôïÏù½Ìïòͽ ÏúÑÌï¥ $REMOTE_USER ÎÄÏàòκ ÏǨÏö©ÌïÝ Ïàò ÏûàÎã§. </simpara> <simpara> ÏúÝÏùòÌïÝ ÏÝêÏùÄ Ïù½Ï¶ùÏù¥ ÌïÑÏöîÌïú ÌéòÏù¥ÏßÄÏôÄ Ïù½Ï¶ùÏù¥ ÌïÑÏöîÏóÜÎäî ÌéòÏù¥ÏßÄÍÄ ÍôÏùÄ ÏÑúξÑÏÉÅÏóê ϰ¥Ïû¨ÌïÝ Îïå, Ïù½Ï¶ùÏù¥ ÌïÑÏöîÏóÜÎäî URLÏùÑ controlÌïÝ Ïàò ÏûàÎäî ÎàÑ͵ÍÄÍÄ, Ïù½Ï¶ùÏù¥ ÌïÑÏöîÌïú URLÏùò ÏïîÌò½Îº ÌõîÏêÎ¥Îäî ;ÉÏùÄ ÎßâÏùÑ Ïàò ÏóÜÎã§Îäî ÏÝêÏù¥Îã§. </simpara> <simpara> NetscapeÏôÄ Internet Explorer ήÎëê 401ÏùëÎãµ ÏîÎìúκ ÏÑúξÑÏóêÏÑú Îõ;åÎêòΩ¥ local browser windowÏùò authentication cacheκ clearÌïúÎã§. ϶â, Ïù¥Í¾ÉÏùÄ "log out"ÍúÎÖêÏù¥ ÎêòÎäî ;ÉÏúºÎ°ú, ÏǨÏö©ÏûêÎì§Î°ú ÌïòÏó¨Í½à usernameͺ ÏïîÌò½Îº Îã§Ïãú ÏûÖÎÝÌïò;å ÌïúÎã§. ÏùºÎÄÎäî Ïù¥Í¾ÉÏùÑ ÌܵÌï¥ loginÏùò "time out"Ïù¥ÎÇò "log-out"ξÑÌäºÏùÑ ÎßåÎìúÎäîÎç ÏǨÏö©ÌïúÎã§ </simpara> <example> <title>HTTP Authentication example forcing a new name/password</title> <programlisting role="php"> <?php function authenticate() { Header( "WWW-authenticate: basic realm=\"Test Authentication System\""); Header( "HTTP/1.0 401 Unauthorized"); echo "You must enter a valid login ID and password to access this resource\n"; exit; } if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER)) ) { authenticate(); } else { echo "Welcome: $PHP_AUTH_USER<BR>"; echo "Old: $OldAuth"; echo "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n"; echo "<INPUT TYPE=HIDDEN NAME=\"SeenBefore\" VALUE=\"1\">\n"; echo "<INPUT TYPE=HIDDEN NAME=\"OldAuth\" VALUE=\"$PHP_AUTH_USER\">\n"; echo "<INPUT TYPE=Submit VALUE=\"Re Authenticate\">\n"; echo "</FORM>\n"; } ?> </programlisting> </example> <simpara> Í ½Îü¨ÎÇò Ïù¥ ÎèôÏûëÏùÄ HTTP Basic authentication ͽϧÄÏóê Î¥ÏûÎêú ;ÉÏùÄ ÏïÑÎãàÎØÄΰú Ïù¥ ͽÎäÏóê Ïùòϰ¥ÌïòÏó¨ÏÑúÎäî ÏïàÎêúÎã§. LynxÏóêÏÑúÎäî 401 ÏÑúÎ¾Ñ ÏùëÎãµÏùÑ ÎõÏïÑÎèÑ authentication ÏÝïΥκ clearÌïòÏßÄ ÏïäÎäîÎã§. ÎîÎùºÏÑú BackÏùÑ ÎàÑÎ¥ÍÝ Îã§Ïãú Forward ξÑÌäºÏùÑ ÎàåÎü¨ÏÑú Îã§Ïãú ÏÝëÍ ºÌïÝ Ïàò ÏûàÎã§.</simpara> <simpara> ÎòêÌïú Ïù¥ Authentication ͽÎäÏùÄ Microsoft's IIS serverÏóêÏÑú CGI versionÏùò PHPκ ÏǨÏö©ÌïÝ Í¾ÏöÏóêÎäî IISÏùò ÏÝúÏïÏúºÎ°úÏù½Ìï¥ ÎèôÏûëÌïòÏßÄ ÏïäÎäîÎã§. </simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/images.xml +++ phpdoc/kr/features/images.xml <chapter id="features.images"> <title>PHPÏóêÏÑú Ïù¥ÎؽÏßÄ ÏÉùÏѱͺ ÏàòÏÝï(Creating and manipulating images)</title> <simpara> PHPÎäî Îã®ÏßÄ HTMLÏúÎÝÏùÑ ÎßåÎìúÎäî ;ÉÎßå ÌïÝ Ïàò ÏûàÎäî ;ÉÏù¥ ÏïÑÎãàÎã§. PHPÎäî GIF image fileÎèÑ ÎßåÎì§ Ïàò ÏûàÏùÑ ÏûàÏùÑ ÎøêÏïÑÎãàÎùº, ÏǨÏö©ÌïòͽÏóê Ìé½Î¶¨Ìïú GIF image streamͼåÏßÄ ÎßåÎì§ Ïàò ÏûàÎã§. Ïù¥Îº ÏúÑÌï¥ÏÑú Ïó¨Îü¨ÎÑÏùÄ PHPκ Ϫ¥ÌååÏùº ÌïÝ Îïå, image Ìï®Ïàòκ ÍÄÏßÄÍÝ ÏûàÎäî GD ÎùºÏù¥Î½åÎü¨Î¶¨Îº Ìè¨Ìï®ÌïòÏó¨Ïïº ÌïúÎã§. GDÏôÄ PHPÎäî ÏǨÏö©ÌïòÎäî Ïù¥ÎؽÏßÄ Ìè¨Îß ÌòïÌÉúÏóê ÎîÎùº Îã§Î½ ÎùºÏù¥Î½åÎü¨Î¶¨ÎèÑ Ïöî͵¨ÌïúÎã§. GDÎäî ξÑÏÝÑ 1.6ÎÄÌÑ GIF Ïù¥ÎؽÏßÄ ÏßÄÏõêÏùÑ ÌïòÏßÄ ÏïäÎäîÎã§. </simpara> <para> <example> <title>PNG creation with PHP</title> <programlisting role="php"> <?php Header("Content-type: image/png"); $string=implode($argv," "); $im = imageCreateFromPng("images/button1.png"); $orange = ImageColorAllocate($im, 220, 210, 60); $px = (imagesx($im)-7.5*strlen($string))/2; ImageString($im,3,$px,9,$string,$orange); ImagePng($im); ImageDestroy($im); ?> </programlisting> </example> ÏúÑÏùò ÏòàÏÝúÎäî <img src="button.php?text"> ÏôÄ ÍôÏùÄ tagÏù¥ ÏûàÎäî ÌéòÏù¥ÏßÄΰúÎÄÌÑ ÎàÎݧÏßÄ;å ÎêÝ Í¾ÉÏù¥Îã§. Í ½Îü¨Î©¥ ÏúÑÏóêÏûàÎäî button.php Ïä§ÌŨζÌä½Îäî "text"ÎùºÎäî Ψ½ÏûêÏó¥ÏùÑ "images/button1.gif"Ïóê Ïò§Î¾ÑÎÝàÏù¥ ÏãúϺú ;ͺ imageÏóê ÏúÎÝÌïúÎã§. Ïù¥ÎÝá;å ÌïòΩ¥ ξÑÌäºÏóê Îì§Ïñ¥ÍÄÎäî ͽÄÏî®Îº Îߧξà ÏÜêÏâ;å ÎîÍøî Ïì½ Ïàò ÏûàÍÝ, ÎòêÌïú Îߧξà Ïù¥ÎؽÏßÄ ÌååÏùºÏùÑ ÎßåÎì§ ÌïÑÏöîÍÄ ÏóÜÏñ¥ Ìö®Ïú®ÏÝÅÏù¥ÍÝ ÍÑÎã®ÌïòÎã§. </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/persistent-connections.xml +++ phpdoc/kr/features/persistent-connections.xml <chapter id="features.persistent-connections"> <title>Persistent Database Connections</title> <simpara> Persistent connections are SQL links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the link. An 'identical' connection is a connection that was opened to the same host, with the same username and the same password (where applicable). </simpara> <simpara> People who aren't thoroughly familiar with the way web servers work and distribute the load may mistake persistent connects for what they're not. In particular, they do <emphasis>not</emphasis> give you an ability to open 'user sessions' on the same SQL link, they do <emphasis>not</emphasis> give you an ability to build up a transaction efficently, and they don't do a whole lot of other things. In fact, to be extremely clear about the subject, persistent connections don't give you <emphasis>any</emphasis> functionality that wasn't possible with their non-persistent brothers. </simpara> <simpara> Why? </simpara> <simpara> This has to do with the way web servers work. There are three ways in which your web server can utilize PHP to generate web pages. </simpara> <simpara> The first method is to use PHP as a CGI "wrapper". When run this way, an instance of the PHP interpreter is created and destroyed for every page request (for a PHP page) to your web server. Because it is destroyed after every request, any resources that it acquires (such as a link to an SQL database server) are closed when it is destroyed. In this case, you do not gain anything from trying to use persistent connections -- they simply don't persist. </simpara> <simpara> The second, and most popular, method is to run PHP as a module in a multiprocess web server, which currently only includes Apache. A multiprocess server typically has one process (the parent) which coordinates a set of processes (its children) who actually do the work of serving up web pages. When each request comes in from a client, it is handed off to one of the children that is not already serving another client. This means that when the same client makes a second request to the server, it may be serviced by a different child process than the first time. What a persistent connection does for you in this case it make it so each child process only needs to connect to your SQL server the first time that it serves a page that makes us of such a connection. When another page then requires a connection to the SQL server, it can reuse the connection that child established earlier. </simpara> <simpara> The last method is to use PHP as a plug-in for a multithreaded web server. Currently this is only theoretical -- PHP does not yet work as a plug-in for any multithreaded web servers. Work is progressing on support for ISAPI, WSAPI, and NSAPI (on Windows), which will all allow PHP to be used as a plug-in on multithreaded servers like Netscape FastTrack, Microsoft's Internet Information Server (IIS), and O'Reilly's WebSite Pro. When this happens, the behavior will be essentially the same as for the multiprocess model described before. </simpara> <simpara> If persistent connections don't have any added functionality, what are they good for? </simpara> <simpara> The answer here is extremely simple -- efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high. Whether or not this overhead is really high depends on many factors. Like, what kind of database it is, whether or not it sits on the same computer on which your web server sits, how loaded the machine the SQL server sits on is and so forth. The bottom line is that if that connection overhead is high, persistent connections help you considerably. They cause the child process to simply connect only once for its entire lifespan, instead of every time it processes a page that requires connecting to the SQL server. This means that for every child that opened a persistent connection will have its own open persistent connection to the server. For example, if you had 20 different child processes that ran a script that made a persistent connection to your SQL server, you'd have 20 different connections to the SQL server, one from each child. </simpara> <simpara> Note, however, that this can have some drawbacks if you are using a database with connection limits that are exceeded by persistant child connections. If your database has a limit of 16 simultaneous connections, and in the course of a busy server session, 17 child threads attempt to connect, one will not be able to. If there are bugs in your scripts which do not allow the connections to shut down (such as infinite loops), a database with only 32 connections may be rapidly swamped. Check your database documentation for information on handling abandoned or idle connections. </simpara> <simpara> An important summary. Persistent connections were designed to have one-to-one mapping to regular connections. That means that you should <emphasis>always</emphasis> be able to replace persistent connections with non-persistent connections, and it won't change the way your script behaves. It <emphasis>may</emphasis> (and probably will) change the efficiency of the script, but not its behavior! </simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/remote-files.xml +++ phpdoc/kr/features/remote-files.xml <chapter id="features.remote-files"> <title>Using remote files</title> <para> As long as support for the "URL fopen wrapper" is enabled when you configure PHP (which it is unless you explicitly pass the <option>--disable-url-fopen-wrapper</option> flag to configure (for versions up to 4.0.3) or set <parameter>allow_url_fopen</parameter> to off in php.ini (for newer versions), you can use HTTP and FTP URLs with most functions that take a filename as a parameter, including the <function>require</function> and <function>include</function> statements. </para> <para> <note> <para> You can't use remote files in <function>include</function> and <function>require</function> statements on Windows. </para> </note> </para> <para> For example, you can use this to open a file on a remote web server, parse the output for the data you want, and then use that data in a database query, or simply to output it in a style matching the rest of your website. </para> <para> <example> <title>Getting the title of a remote page</title> <programlisting role="php"> <![CDATA[ <?php $file = fopen ("http://www.php.net/", "r"); if (!$file) { echo "<p>Unable to open remote file.\n"; exit; } while (!feof ($file)) { $line = fgets ($file, 1024); /* This only works if the title and its tags are on one line */ if (eregi ("<title>(.*)</title>", $line, $out)) { $title = $out[1]; break; } } fclose($file); ?> ]]> </programlisting> </example> </para> <para> You can also write to files on an FTP as long you connect as a user with the correct access rights, and the file doesn't exist already. To connect as a user other than 'anonymous', you need to specify the username (and possibly password) within the URL, such as 'ftp://user:password@ftp.example.com/path/to/file'. (You can use the same sort of syntax to access files via HTTP when they require Basic authentication.) </para> <para> <example> <title>Storing data on a remote server</title> <programlisting role="php"> <![CDATA[ <?php $file = fopen ("ftp://ftp.php.net/incoming/outputfile", "w"); if (!$file) { echo "<p>Unable to open remote file for writing.\n"; exit; } /* Write the data here. */ fputs ($file, "$HTTP_USER_AGENT\n"); fclose ($file); ?> ]]> </programlisting> </example> </para> <para> <note> <para> You might get the idea from the example above to use this technique to write to a remote log, but as mentioned above, you can only write to a new file using the URL fopen() wrappers. To do distributed logging like that, you should take a look at <function>syslog</function>. </para> </note> </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/connection-handling.xml +++ phpdoc/kr/features/connection-handling.xml <chapter id="features.connection-handling"> <title>Connection handling</title> <note> <para>The following applies to 3.0.7 and later.</para> </note> <para> Internally in PHP a connection status is maintained. There are 3 possible states: <itemizedlist> <listitem><simpara>0 - NORMAL</simpara></listitem> <listitem><simpara>1 - ABORTED</simpara></listitem> <listitem><simpara>2 - TIMEOUT</simpara></listitem> </itemizedlist> </para> <simpara> When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button. If the PHP-imposed time limit (see <function>set_time_limit</function>) is hit, the TIMEOUT state flag is turned on.</simpara> <simpara> You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php3.ini directive as well as through the corresponding php3_ignore_user_abort Apache .conf directive or with the <function>ignore_user_abort</function> function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate. The one exception is if you have registered a shutdown function using <function>register_shutdown_function</function>. With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client diconnect you can use the <function>connection_aborted</function> function. This function will return true if the connection was aborted.</simpara> <simpara> Your script can also be terminated by the built-in script timer. The default timeout is 30 seconds. It can be changed using the max_execution_time php3.ini directive or the corresponding php3_max_execution_time Apache .conf directive as well as with the <function>set_time_limit</function> function. When the timer expires the script will be aborted and as with the above client disconnect case, if a shutdown function has been registered it will be called. Within this shutdown function you can check to see if a timeout caused the shutdown function to be called by calling the <function>connection_timeout</function> function. This function will return true if a timeout caused the shutdown function to be called.</simpara> <simpara> One thing to note is that both the ABORTED and the TIMEOUT states can be active at the same time. This is possible if you tell PHP to ignore user aborts. PHP will still note the fact that a user may have broken the connection, but the script will keep running. If it then hits the time limit it will be aborted and your shutdown function, if any, will be called. At this point you will find that <function>connection_timeout</function> and <function>connection_aborted</function> return true. You can also check both states in a single call by using the <function>connection_status</function>. This function returns a bitfield of the active states. So, if both states are active it would return 3, for example.</simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->
Index: phpdoc/kr/features/cookies.xml +++ phpdoc/kr/features/cookies.xml <chapter id="features.cookies"> <title>Cookies</title> <para> PHPÎäî HTTP Cookieκ Ìà¨ÎÖÌïò;å(transparently) ÏßÄÏõêÌïúÎã§. Cookie Ωîϼ¥Îãà϶òÏùÄ Ìä½ÎûòÌǼÏù¥ÎÇò ÏǨÏö©Ïûê ÏãùÎÑ Îì±ÏùÑ ÏúÑÌï¥ Ïõê;© browserÏóê ÏÝÄÏûÎêú ÎçÏù¥ÌÑκ ÎèåÎݧ ÎõÎäî ͺÏÝïÏùÑ ÎßêÌïúÎã§. Ïó¨Îü¨ÎÑÏùÄ cookieκ ÏѧÏÝïÌïòͽ ÏúÑÌï¥ <function>setcookie</function> Ìï®Ïàòκ ÏǨÏö©ÌïÝ Ïàò ÏûàÎã§. CookieÎäî HTTP Ìó§ÎçîÏùò Ìïú ÎÄÎÑÏù¥ÎØÄΰú, <function>setcookie</function> Ìï®ÏàòÎäî νåÎùºÏöÏÝÄΰú Î¥ÎÇ¥Îäî Ïñ¥Îñ§ ÎçÏù¥ÌÑÎ¥Îã§ÎèÑ ÏïûÏóê ÏǨÏö©Ìï¥Ïïº ÌïúÎã§. Ïù¥ ÏÝúÏïÏùÄ <function>header</function> Ìï®ÏàòÏôÄ ÍôÏùÄ ÏÝúÏïÏúºÎ°ú ΥΩ¥ ÎêúÎã§.</para> <para> ÌÅ¥ÎùºÏù¥Ïñ½Ìä½ÍÄ Î¥ÎÇ¥Ï§Ä Î®ÎìÝ cookieÎäî ÏûêÎèôÏÝÅÏúºÎ°ú GETÏù¥ÎÇò POST ΩÏãù ÎçÏù¥ÌÑÏôÄ ÍôÏùÄ PHP ÎÄÏàòΰú ÎÄÌôòÎêúÎã§. ÎßåÏï Ïó¨Îü¨ÎÑÏù¥ ÎèôÏùºÌïú cookieÏóê Ïó¨Îü¨ ÍíÏùÑ ÏÝÄÏûÌïòÍÝ ÏãÎã§Î©¥ CookieÏù¥Î¶ÑÏóê <emphasis>[]</emphasis>κ ÎçîÌïòΩ¥ ÎêúÎã§. ÏûêÏѽÌïú ;ÉÏùÄ <function>setcookie</function> Ìï®Ïàò ÏѧÎÖÏùÑ Ï½Ï°ÌïòÏûê. </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/error-handling.xml +++ phpdoc/kr/features/error-handling.xml <chapter id="features.error-handling"> <title>Error Handling</title> <para> PHPÏóêÎäî Îã§Ïùåͺ ÍôÏùÄ Ïó¨Îü¨ ÏóêÎü¨ÏôÄ Í¾ÍÝ ÌòïÌÉúÍÄ ÏûàÎã§.: <table> <title>PHP error types</title> <tgroup cols="4"> <thead> <row> <entry>Value</entry> <entry>Constant</entry> <entry>Description</entry> <entry>Note</entry> </row> </thead> <tbody> <row> <entry>1</entry> <entry>E_ERROR</entry> <entry>Normal Function Errors (ÏùºÎòÏÝÅÏù½ ÏóêÎü¨)</entry> <entry/> </row> <row> <entry>2</entry> <entry>E_WARNING</entry> <entry>Normal Warnings (ÏùºÎòÏÝÅÏù½ ;ÍÝ)</entry> <entry/> </row> <row> <entry>4</entry> <entry>E_PARSE</entry> <entry>Parser Errors (Ψ½Î¾ï ÏóêÎü¨)</entry> <entry/> </row> <row> <entry>8</entry> <entry>E_NOTICE </entry> <entry> Notices (Ψ¥ÏãúÌïÝ Ïàò ÏûàÎäî ÏïåζºÏù¥ÏßÄÎßå ξÑÍ ½Ïùò ÍÄÎäÏѱÏùÑ ÍÄÏßÄÍÝ ÏûàÎäî ;Ïö) </entry> <entry/> </row> <row> <entry>16</entry> <entry>E_CORE_ERROR</entry> <entry>fatal errors that occur during PHP's initial startup (PHPÍÄ Ï¾òÏùå ÏãúÏûëÎêÝ Îïå ÎúÏÉùÌïú ϼòÎÖÏÝÅ ÏóêÎü¨)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>32</entry> <entry>E_CORE_WARNING</entry> <entry>warnings (non fatal errors) that occur during PHP's initial startup (PHPÍÄ Ï¾òÏùå ÏãúÏûëÎêÝ Îïå ÎúÏÉùÌïú ϼòÎÖÏÝÅÏù¥ÏßÄ ÏïäÏùÄ Í¾ÍÝ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>64</entry> <entry>E_COMPILE_ERROR</entry> <entry>fatal compile-time errors (Ϫ¥ÌååÏùºÏãú ÏÉùͽ¥ ϼòÎÖÏÝÅ ÏóêÎü¨)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>128</entry> <entry>E_COMPILE_WARNING</entry> <entry>compile-time warnings (non fatal errors) (Ϫ¥ÌååÏùºÏãú ÎúÏÉùÌïú ϼòÎÖÏÝÅÏù¥ÏßÄ ÏïäÏùÄ Í¾ÍÝ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>256</entry> <entry>E_USER_ERROR</entry> <entry>user-generated error message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ ÏóêÎü¨ ΩîÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>512</entry> <entry>E_USER_WARNING</entry> <entry>user-generated warning message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ Í¾ÍÝ Î©îÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry>1024</entry> <entry>E_USER_NOTICE </entry> <entry>user-generated notice message (ÏǨÏö©ÏûêÍÄ ÎßåÎìÝ Ïïåζº ΩîÏѽÏßÄ)</entry> <entry>PHP 4 only</entry> </row> <row> <entry/> <entry>E_ALL</entry> <entry>all of the above, as supported (ÏßÄÏõêÍÄÎäÌïú ÏúÑÏùò Í¾É Î®Îëê)</entry> <entry/> </row> </tbody> </tgroup> </table> </para> <para> The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the <link linkend="language.operators.bitwise">bitwise operators</link> to combine these values or mask out certain types of errors. Note that only '|', '~', '!', and '&' will be understood within <filename>php.ini</filename>, however, and that no bitwise operators will be understood within <filename>php3.ini</filename>. </para> <para> In PHP 4, the default <link linkend="ini.error-reporting">error_reporting</link> setting is <literal>E_ALL & ~E_NOTICE</literal>, meaning to display all errors and warnings which are not E_NOTICE-level. In PHP 3, the default setting is <literal>(E_ERROR | E_WARNING | E_PARSE)</literal>, meaning the same thing. Note, however, that since constants are not supported in PHP 3's <filename>php3.ini</filename>, the <link linkend="ini.error-reporting">error_reporting</link> setting there must be numeric; hence, it is <literal>7</literal>. </para> <para> The initial setting can be changed in the ini file with the <link linkend="ini.error-reporting">error_reporting</link> directive, in your Apache <filename>httpd.conf</filename> file with the php_error_reporting (php3_error_reporting for PHP 3) directive, and lastly it may be set at runtime within a script by using the <function>error_reporting</function> function. </para> <warning> <para> When upgrading code or servers from PHP 3 to PHP 4 you should check these settings and calls to <function>error_reporting</function> or you might disable reporting the new error types, especially E_COMPILE_ERROR. This may lead to empty documents without any feedback of what happened or where to look for the problem. </para> </warning> <para> ήÎìÝ <link linkend="language.expressions">PHP ÌëúÌòÑÏãù(expression)</link>ÏùÄ "@"κ ÏïûÏóê ÎôÏù¥ÍÝ Ìò½ÏúÎêòΩ¥ error reportingÏùÑ ÌïòÏßÄ ÏïäÎäîÎã§. ÎßåÏï <link linkend="ini.track-errors">track_errors</link> ÏòµÏÖòÏù¥ Enabledΰú ÎêòÏñ¥ ÏûàÍÝ Ìï¥Î㼠Ψ½ÏûÏóêÏÑú ÏóêÎü¨ÍÄ ÎúÏÉùÌñàÎã§Î©¥, $php_errormsgÎùºÎäî ÏÝÑÏóÎÄÏàòÏóê ÏóêÎü¨ ΩîÏãúÏßÄÍÄ Îã¥Í¾® Ïûà;å ÎêúÎã§. </para> <warning> <para> Currently the <link linkend="language.operators.errorcontrol">@ error-control operator</link> prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use <link linkend="language.operators.errorcontrol">@</link> to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. </para> </warning> <para> Below we can see an example of using the error handling capabilities in PHP. We define a error handling function which logs the information into a file (using an XML format), and e-mails the developer in case a critical error in the logic happens. <example> <title>Using error handling in a script</title> <programlisting role="php"> <?php // we will do our own error handling error_reporting(0); // user defined error handling function function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) { // timestamp for the error entry $dt = date("Y-m-d H:i:s (T)"); // define an assoc array of error string // in reality the only entries we should // consider are 2,8,256,512 and 1024 $errortype = array ( 1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024=> "User Notice" ); // set of errors for which a var trace will be saved $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "<errorentry>\n"; $err .= "\t<datetime>".$dt."</datetime>\n"; $err .= "\t<errornum>".$errno."</errnumber>\n"; $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n"; $err .= "\t<errormsg>".$errmsg."</errormsg>\n"; $err .= "\t<scriptname>".$filename."</scriptname>\n"; $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n"; if (in_array($errno, $user_errors)) $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n"; $err .= "</errorentry>\n\n"; // for testing // echo $err; // save to the error log, and e-mail me if there is a critical user error error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) mail("phpdev@mydomain.com","Critical User Error",$err); } function distance ($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } $d += $c2*$c2 - $c1*$c1; } return sqrt($d); } $old_error_handler = set_error_handler("userErrorHandler"); // undefined constant, generates a warning $t = I_AM_NOT_DEFINED; // define some "vectors" $a = array(2,3,"foo"); $b = array(5.5, 4.3, -1.6); $c = array (1,-3); // generate a user error $t1 = distance($c,$b)."\n"; // generate another user error $t2 = distance($b,"i am not an array")."\n"; // generate a warning $t3 = distance($a,$b)."\n"; ?> </programlisting> </example> This is just a simple example showing how to use the <link linkend="ref.errorfunc">Error Handling and Logging functions</link>. </para> <para> See also <function>error_reporting</function>, <function>error_log</function>, <function>set_error_handler</function>, <function>restore_error_handler</function>, <function>trigger_error</function>, <function>user_error</function> </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/file-upload.xml +++ phpdoc/kr/features/file-upload.xml <chapter id="features.file-upload"> <title>Handling file uploads</title> <sect1 id="features.file-upload.post-method"> <title>POST method uploads</title> <simpara> PHP is capable of receiving file uploads from any RFC-1867 compliant browser (which includes Netscape Navigator 3 or later, Microsoft Internet Explorer 3 with a patch from Microsoft, or later without a patch). This feature lets people upload both text and binary files. With PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded. </simpara> <para> Note that PHP also supports PUT-method file uploads as used by Netscape Composer and W3C's Amaya clients. See the <link linkend="features.file-upload.put-method">PUT Method Support</link> for more details. </para> <para> A file upload screen can be built by creating a special form which looks something like this: <example> <title>File Upload Form</title> <programlisting> <FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000"> Send this file: <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" VALUE="Send File"> </FORM> </programlisting> </example> The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden field must precede the file input field and its value is the maximum filesize accepted. The value is in bytes. </para> <para> In PHP 3, the following variables will be defined within the destination script upon a successful upload, assuming that <link linkend="ini.register-globals">register_globals</link> is turned on in <filename>php3.ini</filename>. If <link linkend="ini.track-vars">track_vars</link> is turned on, they will also be available in PHP 3 within the global array <varname>$HTTP_POST_VARS</varname>. Note that the following variable names assume the use of the file upload name 'userfile', as used in the example above: <itemizedlist> <listitem> <simpara> <varname>$userfile</varname> - The temporary filename in which the uploaded file was stored on the server machine. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_name</varname> - The original name or path of the file on the sender's system. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_size</varname> - The size of the uploaded file in bytes. </simpara> </listitem> <listitem> <simpara> <varname>$userfile_type</varname> - The mime type of the file if the browser provided this information. An example would be "image/gif". </simpara> </listitem> </itemizedlist> Note that the "$userfile" part of the above variables is whatever the name of the INPUT field of TYPE=file is in the upload form. In the above upload form example, we chose to call it "userfile" </para> <para> In PHP 4, the behaviour is slightly different, in that the new global array <varname>$HTTP_POST_FILES</varname> is provided to contain the uploaded file information. This is still only available if <link linkend="ini.track-vars">track_vars</link> is turned on, but <link linkend="ini.track-vars">track_vars</link> is always turned on in versions of PHP after PHP 4.0.2. </para> <para> The contents of <varname>$HTTP_POST_FILES</varname> are as follows. Note that this assumes the use of the file upload name 'userfile', as used in the example above: <variablelist> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['name']</varname></term> <listitem> <para> The original name of the file on the client machine. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['type']</varname></term> <listitem> <para> The mime type of the file, if the browser provided this information. An example would be <literal>"image/gif"</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['size']</varname></term> <listitem> <para> The size, in bytes, of the uploaded file. </para> </listitem> </varlistentry> <varlistentry> <term><varname>$HTTP_POST_FILES['userfile']['tmp_name']</varname></term> <listitem> <para> The temporary filename of the file in which the uploaded file was stored on the server. </para> </listitem> </varlistentry> </variablelist> </para> <para> Files will by default be stored in the server's default temporary directory, unless another location has been given with the <link linkend="ini.upload-tmp-dir">upload_tmp_dir</link> directive in <filename>php.ini</filename>. The server's default directory can be changed by setting the environment variable <envar>TMPDIR</envar> in the environment in which PHP runs. Setting it using <function>putenv</function> from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well. <example> <title>Validating file uploads</title> <para> The following examples are for versions of PHP 3 greater than 3.0.16, and versions of PHP 4 greater than 4.0.2. See the function entries for <function>is_uploaded_file</function> and <function>move_uploaded_file</function>. </para> <programlisting role="php"> <?php if (is_uploaded_file($userfile)) { copy($userfile, "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack: filename '$userfile'."; } /* ...or... */ move_uploaded_file($userfile, "/place/to/put/uploaded/file"); ?> </programlisting> <para> For earlier versions of PHP, you'll need to do something like the following. <note> <para> This will <emphasis>not</emphasis> work in versions of PHP 4 after 4.0.2. It depends on internal functionality of PHP which changed after that version. </para> </note> </para> <programlisting role="php"> <?php /* Userland test for uploaded file. */ function is_uploaded_file($filename) { if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { $tmp_file = dirname(tempnam('', '')); } $tmp_file .= '/' . basename($filename); /* User might have trailing slash in php.ini... */ return (ereg_replace('/+', '/', $tmp_file) == $filename); } if (is_uploaded_file($userfile)) { copy($userfile, "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack: filename '$userfile'."; } ?> </programlisting> </example> </para> <simpara> The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can for example use the <varname>$file_size</varname> variable to throw away any files that are either too small or too big. You could use the <varname>$file_type</varname> variable to throw away any files that didn't match a certain type criteria. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere. </simpara> <simpara> The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed. </simpara> </sect1> <sect1 id="features.file-upload.common-pitfalls"> <title>Common Pitfalls</title> <simpara> The MAX_FILE_SIZE item cannot specify a file size greater than the file size that has been set in the upload_max_filesize in the PHP 3.ini file or the corresponding php3_upload_max_filesize Apache .conf directive. The default is 2 Megabytes. </simpara> <simpara> Not validating which file you operate on may mean that users can access sensitive information in other directories. </simpara> <simpara> Please note that the CERN httpd seems to strip off everything starting at the first whitespace in the content-type mime header it gets from the client. As long as this is the case, CERN httpd will not support the file upload feature. </simpara> </sect1> <sect1 id="feature-fileupload.multiple"> <title>Uploading multiple files</title> <simpara> It is possible to upload multiple files simultaneously and have the information organized automatically in arrays for you. To do so, you need to use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes: </simpara> <note> <para> Support for multiple file uploads was added in version 3.0.10. </para> </note> <para> <example> <title>Uploading multiple files</title> <programlisting> <form action="file-upload.php" method="post" enctype="multipart/form-data"> Send these files:<br> <input name="userfile[]" type="file"><br> <input name="userfile[]" type="file"><br> <input type="submit" value="Send files"> </form> </programlisting> </example> </para> <simpara> When the above form is submitted, the arrays <computeroutput>$userfile</computeroutput>, <computeroutput>$userfile_name</computeroutput>, and <computeroutput>$userfile_size</computeroutput> will be formed in the global scope (as well as in $HTTP_POST_FILES ($HTTP_POST_VARS in PHP 3)). Each of these will be a numerically indexed array of the appropriate values for the submitted files. </simpara> <simpara> For instance, assume that the filenames <filename>/home/test/review.html</filename> and <filename>/home/test/xwp.out</filename> are submitted. In this case, <computeroutput>$userfile_name[0]</computeroutput> would contain the value <computeroutput>review.html</computeroutput>, and <computeroutput>$userfile_name[1]</computeroutput> would contain the value <computeroutput>xwp.out</computeroutput>. Similarly, <computeroutput>$userfile_size[0]</computeroutput> would contain <filename>review.html</filename>'s filesize, and so forth. </simpara> <simpara> <computeroutput>$userfile['name'][0]</computeroutput>, <computeroutput>$userfile['tmp_name'][0]</computeroutput>, <computeroutput>$userfile['size'][0]</computeroutput>, and <computeroutput>$userfile['type'][0]</computeroutput> are also set. </simpara> </sect1> <sect1 id="features.file-upload.put-method"> <title>PUT method support</title> <para> PHP provides support for the HTTP PUT method used by clients such as Netscape Composer and W3C Amaya. PUT requests are much simpler than a file upload and they look something like this: <informalexample> <programlisting> PUT /path/filename.html HTTP/1.1 </programlisting> </informalexample> </para> <para> This would normally mean that the remote client would like to save the content that follows as: /path/filename.html in your web tree. It is obviously not a good idea for Apache or PHP to automatically let everybody overwrite any files in your web tree. So, to handle such a request you have to first tell your web server that you want a certain PHP script to handle the request. In Apache you do this with the <emphasis>Script</emphasis> directive. It can be placed almost anywhere in your Apache configuration file. A common place is inside a <Directory> block or perhaps inside a <Virtualhost> block. A line like this would do the trick: <informalexample> <programlisting> Script PUT /put.php3 </programlisting> </informalexample> </para> <simpara> This tells Apache to send all PUT requests for URIs that match the context in which you put this line to the put.php3 script. This assumes, of course, that you have PHP enabled for the .php3 extension and PHP is active. </simpara> <simpara> Inside your put.php3 file you would then do something like this: </simpara> <para> <informalexample><programlisting> <?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?> </programlisting></informalexample> </para> <simpara> This would copy the file to the location requested by the remote client. You would probably want to perform some checks and/or authenticate the user before performing this file copy. The only trick here is that when PHP sees a PUT-method request it stores the uploaded file in a temporary file just like those handled but the <link linkend="features.file-upload.post-method">POST-method</link>. When the request ends, this temporary file is deleted. So, your PUT handling PHP script has to copy that file somewhere. The filename of this temporary file is in the $PHP_PUT_FILENAME variable, and you can see the suggested destination filename in the $REQUEST_URI (may vary on non-Apache web servers). This destination filename is the one that the remote client specified. You do not have to listen to this client. You could, for example, copy all uploaded files to a special uploads directory. </simpara> </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/http-auth.xml +++ phpdoc/kr/features/http-auth.xml <chapter id="features.http-auth"> <title>HTTP authentication with PHP</title> <simpara> (ÏóÏûêÏ£º. HTTP authenticationÏù¥ÎûÄ Web ClientÏóê;å IDÏôÄ Passwordκ ÏûÖÎÝÎõÏïÑ, Í ½ IDÏôÄ Passwordΰú WebΨ½ÏÑúÏóê ÏÝëÍ ºÏùÑ ÌóàÍÄ, ÎàÌóàÌïòÎäî ͽÎäÏùÑ ÎßêÌïúÎã§. ÏûêÏѽÌûà ÏïåÍÝ ÏãÎã§Î©¥ RFC1945Ïùò Authentication ÎÄÎÑÏùÑ Ï½ÍÝÌïòͽ ÎîÎûÄÎã§. http://pec.etri.re.kr/!qkim/HTTP/Ïóê ÌïúÍ½Ä Î¾àÏó Ψ½ÏÑúÎèÑ ÏûàÏúºÎãà ϽϰÌïòÏûê.) </simpara> <simpara> PHPκ ÏǨÏö©Ìïú HTTP Ïù½Ï¶ùÏùÄ Apache ήÎìàΰú ÏǨÏö©ÎêÝ ÎïåÎßå ÎèôÏûëÌïúÎã§. CGI ξÑÏݺÏóêÏÑúÎäî Ïù¥ ͽÎäÏùÑ ÏǨÏö©ÌïÝ Ïàò ÏóÜÎã§. Apache ήÎìàÏùò PHP Ïä§ÌŨζÌä½ÏóêÏÑú <function>Header</function>ÎùºÎäî Ìï®Ïàòκ ÏǨÏö©ÌïòΩ¥ Client νåÎùºÏöÏÝÄÏóê;å Usernameͺ Passwordκ ÏûÖÎÝÎõÎäî ÏúàÎèÑÏöκ ÎùÑÏöÎèÑΰù ÌïòÎäî "Ïù½Ï¶ù Ïöî͵¨"("Authentication Required") ΩîÏãúÏßÄκ Î¥ÎǺ Ïàò ÏûàÎã§. ÏùºÎã® ÏǨÏö©ÏûêÍÄ Usernameͺ Passwordκ ÏûÖÎÝÌïòΩ¥, user name, password, authentication typeÏùò ÍíÏùÑ ÍÄÏßÄÎäî $PHP_AUTH_USER, $PHP_AUTH_PW, $PHP_AUTH_TYPEÏùò 3ÍúÏùò ÎÄÏàòκ ÍÄÏßÄÍÝ Ìï¥Îã¼ URL(PHP Ïä§ÌŨζÌä½Îº Ìè¨Ìï®Ìïú)Ïù¥ Îã§Ïãú Îàζ¨ÏõåÏßÑÎã§. ÌòÑÏû¨ authentication typeÏùÄ "Basic"ÎßåÏù¥ ÏßÄÏõêÎêúÎã§. ÏûêÏѽÌïú ÏǨÏö©Î¾ïÏùÄ <function>Header</function> Ìï®Ïàòκ ÏÇ¥Ìé¥ Î¥Ïûê.</simpara> <para> client authenticationÏùÑ ÏǨÏö©ÌïòÏó¨ Í ½ ÏûÖÎÝÎêú ÍíÏùÑ ÏúÎÝÌïòÎäî ÏòàÏÝúÍÄ ÏïÑÎûòÏóê ÏûàÎã§. : <example> <title>HTTP Authentication example</title> <programlisting role="php"> <?php if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic realm=\"My Realm\""); Header("HTTP/1.0 401 Unauthorized"); echo "Text to send if user hits Cancel button\n"; exit; } else { echo "Hello $PHP_AUTH_USER.<P>"; echo "You entered $PHP_AUTH_PW as your password.<P>"; } ?> </programlisting> </example> </para> <para> Ïó¨Îü¨ÎÑÏùÄ $PHP_AUTH_USER ÏôÄ $PHP_AUTH_PWκ Îã®ÏàúÌûà ÏúÎÝÌïòÎäî ÎåÄÏãÝ, ÏǨÏö©ÏûêÏùò ÏãùÎÑÏùÑ ÏúÑÌï¥ usernameͺ passwordκ ÏǨÏö©Ìïòͽκ ÏõêÌïÝ Í¾ÉÏù¥Îã§. Ïù¥ÎïåÎäî DatabaseÏóê QueryÌïòͱÎÇò ÏßÅÏÝë dbm ÌååÏùºÏóêÏÑú ÏæÏïÑÎ¥Îäî Îì±Ïùò ΩξïÏúºÎ°ú ÍÄÎäÌïÝ Í¾ÉÏù¥Îã§.</para> <para> Internet Explorer browserÏóêÏÑúÎäî ξÑÍ ½Î°ú Ïù½Ìï¥ HeaderÏùò ÏàúÏÑúÍÄ Îß§Ïö ͼåÎã§Î°Îã§. <emphasis>WWW-Authenticate</emphasis>κ <errorcode>HTTP/1.0 401</errorcode>Î¥Î㧠ήºÏÝÄ Î¥ÎÇ¥Îäî ;ÉÏù¥ ÌòÑÏû¨ ÍÄÎäÌïú Ìä½Î¶ÏúºÎ°ú Î¥Ïù½Îã§. </para> <simpara> μÑÎÄξàÌò½Ïùò ÏúÝÏúÏùÑ ÏöÎݧÌïòÏó¨ HTTPÏóêÏÑú ÏÝú͵ÌïòÎäî Ïù½Ï¶ùÏùÑ ÏǨÏö©ÌïòÎäî ÎåÄÏãÝ Í½Ï°¥Ïùò Ïô½ÎÄ Î©îϼ¥Îãà϶òÏùÑ ÏǨÏö©ÌïÝ Í¾ÏöÏóêÎäî ΨºÎ°Ý PHP_AUTH ÎÄÏàòÎäî ÏѧÏÝïÎêòÏßÄ ÏïäÎäîÎã§. Ïù¥Îü;Ïö externally-authenticated userκ ÌôïÏù½Ìïòͽ ÏúÑÌï¥ $REMOTE_USER ÎÄÏàòκ ÏǨÏö©ÌïÝ Ïàò ÏûàÎã§. </simpara> <simpara> ÏúÝÏùòÌïÝ ÏÝêÏùÄ Ïù½Ï¶ùÏù¥ ÌïÑÏöîÌïú ÌéòÏù¥ÏßÄÏôÄ Ïù½Ï¶ùÏù¥ ÌïÑÏöîÏóÜÎäî ÌéòÏù¥ÏßÄÍÄ ÍôÏùÄ ÏÑúξÑÏÉÅÏóê ϰ¥Ïû¨ÌïÝ Îïå, Ïù½Ï¶ùÏù¥ ÌïÑÏöîÏóÜÎäî URLÏùÑ controlÌïÝ Ïàò ÏûàÎäî ÎàÑ͵ÍÄÍÄ, Ïù½Ï¶ùÏù¥ ÌïÑÏöîÌïú URLÏùò ÏïîÌò½Îº ÌõîÏêÎ¥Îäî ;ÉÏùÄ ÎßâÏùÑ Ïàò ÏóÜÎã§Îäî ÏÝêÏù¥Îã§. </simpara> <simpara> NetscapeÏôÄ Internet Explorer ήÎëê 401ÏùëÎãµ ÏîÎìúκ ÏÑúξÑÏóêÏÑú Îõ;åÎêòΩ¥ local browser windowÏùò authentication cacheκ clearÌïúÎã§. ϶â, Ïù¥Í¾ÉÏùÄ "log out"ÍúÎÖêÏù¥ ÎêòÎäî ;ÉÏúºÎ°ú, ÏǨÏö©ÏûêÎì§Î°ú ÌïòÏó¨Í½à usernameͺ ÏïîÌò½Îº Îã§Ïãú ÏûÖÎÝÌïò;å ÌïúÎã§. ÏùºÎÄÎäî Ïù¥Í¾ÉÏùÑ ÌܵÌï¥ loginÏùò "time out"Ïù¥ÎÇò "log-out"ξÑÌäºÏùÑ ÎßåÎìúÎäîÎç ÏǨÏö©ÌïúÎã§ </simpara> <example> <title>HTTP Authentication example forcing a new name/password</title> <programlisting role="php"> <?php function authenticate() { Header( "WWW-authenticate: basic realm=\"Test Authentication System\""); Header( "HTTP/1.0 401 Unauthorized"); echo "You must enter a valid login ID and password to access this resource\n"; exit; } if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER)) ) { authenticate(); } else { echo "Welcome: $PHP_AUTH_USER<BR>"; echo "Old: $OldAuth"; echo "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n"; echo "<INPUT TYPE=HIDDEN NAME=\"SeenBefore\" VALUE=\"1\">\n"; echo "<INPUT TYPE=HIDDEN NAME=\"OldAuth\" VALUE=\"$PHP_AUTH_USER\">\n"; echo "<INPUT TYPE=Submit VALUE=\"Re Authenticate\">\n"; echo "</FORM>\n"; } ?> </programlisting> </example> <simpara> Í ½Îü¨ÎÇò Ïù¥ ÎèôÏûëÏùÄ HTTP Basic authentication ͽϧÄÏóê Î¥ÏûÎêú ;ÉÏùÄ ÏïÑÎãàÎØÄΰú Ïù¥ ͽÎäÏóê Ïùòϰ¥ÌïòÏó¨ÏÑúÎäî ÏïàÎêúÎã§. LynxÏóêÏÑúÎäî 401 ÏÑúÎ¾Ñ ÏùëÎãµÏùÑ ÎõÏïÑÎèÑ authentication ÏÝïΥκ clearÌïòÏßÄ ÏïäÎäîÎã§. ÎîÎùºÏÑú BackÏùÑ ÎàÑÎ¥ÍÝ Îã§Ïãú Forward ξÑÌäºÏùÑ ÎàåÎü¨ÏÑú Îã§Ïãú ÏÝëÍ ºÌïÝ Ïàò ÏûàÎã§.</simpara> <simpara> ÎòêÌïú Ïù¥ Authentication ͽÎäÏùÄ Microsoft's IIS serverÏóêÏÑú CGI versionÏùò PHPκ ÏǨÏö©ÌïÝ Í¾ÏöÏóêÎäî IISÏùò ÏÝúÏïÏúºÎ°úÏù½Ìï¥ ÎèôÏûëÌïòÏßÄ ÏïäÎäîÎã§. </simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/images.xml +++ phpdoc/kr/features/images.xml <chapter id="features.images"> <title>PHPÏóêÏÑú Ïù¥ÎؽÏßÄ ÏÉùÏѱͺ ÏàòÏÝï(Creating and manipulating images)</title> <simpara> PHPÎäî Îã®ÏßÄ HTMLÏúÎÝÏùÑ ÎßåÎìúÎäî ;ÉÎßå ÌïÝ Ïàò ÏûàÎäî ;ÉÏù¥ ÏïÑÎãàÎã§. PHPÎäî GIF image fileÎèÑ ÎßåÎì§ Ïàò ÏûàÏùÑ ÏûàÏùÑ ÎøêÏïÑÎãàÎùº, ÏǨÏö©ÌïòͽÏóê Ìé½Î¶¨Ìïú GIF image streamͼåÏßÄ ÎßåÎì§ Ïàò ÏûàÎã§. Ïù¥Îº ÏúÑÌï¥ÏÑú Ïó¨Îü¨ÎÑÏùÄ PHPκ Ϫ¥ÌååÏùº ÌïÝ Îïå, image Ìï®Ïàòκ ÍÄÏßÄÍÝ ÏûàÎäî GD ÎùºÏù¥Î½åÎü¨Î¶¨Îº Ìè¨Ìï®ÌïòÏó¨Ïïº ÌïúÎã§. GDÏôÄ PHPÎäî ÏǨÏö©ÌïòÎäî Ïù¥ÎؽÏßÄ Ìè¨Îß ÌòïÌÉúÏóê ÎîÎùº Îã§Î½ ÎùºÏù¥Î½åÎü¨Î¶¨ÎèÑ Ïöî͵¨ÌïúÎã§. GDÎäî ξÑÏÝÑ 1.6ÎÄÌÑ GIF Ïù¥ÎؽÏßÄ ÏßÄÏõêÏùÑ ÌïòÏßÄ ÏïäÎäîÎã§. </simpara> <para> <example> <title>PNG creation with PHP</title> <programlisting role="php"> <?php Header("Content-type: image/png"); $string=implode($argv," "); $im = imageCreateFromPng("images/button1.png"); $orange = ImageColorAllocate($im, 220, 210, 60); $px = (imagesx($im)-7.5*strlen($string))/2; ImageString($im,3,$px,9,$string,$orange); ImagePng($im); ImageDestroy($im); ?> </programlisting> </example> ÏúÑÏùò ÏòàÏÝúÎäî <img src="button.php?text"> ÏôÄ ÍôÏùÄ tagÏù¥ ÏûàÎäî ÌéòÏù¥ÏßÄΰúÎÄÌÑ ÎàÎݧÏßÄ;å ÎêÝ Í¾ÉÏù¥Îã§. Í ½Îü¨Î©¥ ÏúÑÏóêÏûàÎäî button.php Ïä§ÌŨζÌä½Îäî "text"ÎùºÎäî Ψ½ÏûêÏó¥ÏùÑ "images/button1.gif"Ïóê Ïò§Î¾ÑÎÝàÏù¥ ÏãúϺú ;ͺ imageÏóê ÏúÎÝÌïúÎã§. Ïù¥ÎÝá;å ÌïòΩ¥ ξÑÌäºÏóê Îì§Ïñ¥ÍÄÎäî ͽÄÏî®Îº Îߧξà ÏÜêÏâ;å ÎîÍøî Ïì½ Ïàò ÏûàÍÝ, ÎòêÌïú Îߧξà Ïù¥ÎؽÏßÄ ÌååÏùºÏùÑ ÎßåÎì§ ÌïÑÏöîÍÄ ÏóÜÏñ¥ Ìö®Ïú®ÏÝÅÏù¥ÍÝ ÍÑÎã®ÌïòÎã§. </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/persistent-connections.xml +++ phpdoc/kr/features/persistent-connections.xml <chapter id="features.persistent-connections"> <title>Persistent Database Connections</title> <simpara> Persistent connections are SQL links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the link. An 'identical' connection is a connection that was opened to the same host, with the same username and the same password (where applicable). </simpara> <simpara> People who aren't thoroughly familiar with the way web servers work and distribute the load may mistake persistent connects for what they're not. In particular, they do <emphasis>not</emphasis> give you an ability to open 'user sessions' on the same SQL link, they do <emphasis>not</emphasis> give you an ability to build up a transaction efficently, and they don't do a whole lot of other things. In fact, to be extremely clear about the subject, persistent connections don't give you <emphasis>any</emphasis> functionality that wasn't possible with their non-persistent brothers. </simpara> <simpara> Why? </simpara> <simpara> This has to do with the way web servers work. There are three ways in which your web server can utilize PHP to generate web pages. </simpara> <simpara> The first method is to use PHP as a CGI "wrapper". When run this way, an instance of the PHP interpreter is created and destroyed for every page request (for a PHP page) to your web server. Because it is destroyed after every request, any resources that it acquires (such as a link to an SQL database server) are closed when it is destroyed. In this case, you do not gain anything from trying to use persistent connections -- they simply don't persist. </simpara> <simpara> The second, and most popular, method is to run PHP as a module in a multiprocess web server, which currently only includes Apache. A multiprocess server typically has one process (the parent) which coordinates a set of processes (its children) who actually do the work of serving up web pages. When each request comes in from a client, it is handed off to one of the children that is not already serving another client. This means that when the same client makes a second request to the server, it may be serviced by a different child process than the first time. What a persistent connection does for you in this case it make it so each child process only needs to connect to your SQL server the first time that it serves a page that makes us of such a connection. When another page then requires a connection to the SQL server, it can reuse the connection that child established earlier. </simpara> <simpara> The last method is to use PHP as a plug-in for a multithreaded web server. Currently this is only theoretical -- PHP does not yet work as a plug-in for any multithreaded web servers. Work is progressing on support for ISAPI, WSAPI, and NSAPI (on Windows), which will all allow PHP to be used as a plug-in on multithreaded servers like Netscape FastTrack, Microsoft's Internet Information Server (IIS), and O'Reilly's WebSite Pro. When this happens, the behavior will be essentially the same as for the multiprocess model described before. </simpara> <simpara> If persistent connections don't have any added functionality, what are they good for? </simpara> <simpara> The answer here is extremely simple -- efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high. Whether or not this overhead is really high depends on many factors. Like, what kind of database it is, whether or not it sits on the same computer on which your web server sits, how loaded the machine the SQL server sits on is and so forth. The bottom line is that if that connection overhead is high, persistent connections help you considerably. They cause the child process to simply connect only once for its entire lifespan, instead of every time it processes a page that requires connecting to the SQL server. This means that for every child that opened a persistent connection will have its own open persistent connection to the server. For example, if you had 20 different child processes that ran a script that made a persistent connection to your SQL server, you'd have 20 different connections to the SQL server, one from each child. </simpara> <simpara> Note, however, that this can have some drawbacks if you are using a database with connection limits that are exceeded by persistant child connections. If your database has a limit of 16 simultaneous connections, and in the course of a busy server session, 17 child threads attempt to connect, one will not be able to. If there are bugs in your scripts which do not allow the connections to shut down (such as infinite loops), a database with only 32 connections may be rapidly swamped. Check your database documentation for information on handling abandoned or idle connections. </simpara> <simpara> An important summary. Persistent connections were designed to have one-to-one mapping to regular connections. That means that you should <emphasis>always</emphasis> be able to replace persistent connections with non-persistent connections, and it won't change the way your script behaves. It <emphasis>may</emphasis> (and probably will) change the efficiency of the script, but not its behavior! </simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/remote-files.xml +++ phpdoc/kr/features/remote-files.xml <chapter id="features.remote-files"> <title>Using remote files</title> <para> As long as support for the "URL fopen wrapper" is enabled when you configure PHP (which it is unless you explicitly pass the <option>--disable-url-fopen-wrapper</option> flag to configure (for versions up to 4.0.3) or set <parameter>allow_url_fopen</parameter> to off in php.ini (for newer versions), you can use HTTP and FTP URLs with most functions that take a filename as a parameter, including the <function>require</function> and <function>include</function> statements. </para> <para> <note> <para> You can't use remote files in <function>include</function> and <function>require</function> statements on Windows. </para> </note> </para> <para> For example, you can use this to open a file on a remote web server, parse the output for the data you want, and then use that data in a database query, or simply to output it in a style matching the rest of your website. </para> <para> <example> <title>Getting the title of a remote page</title> <programlisting role="php"> <![CDATA[ <?php $file = fopen ("http://www.php.net/", "r"); if (!$file) { echo "<p>Unable to open remote file.\n"; exit; } while (!feof ($file)) { $line = fgets ($file, 1024); /* This only works if the title and its tags are on one line */ if (eregi ("<title>(.*)</title>", $line, $out)) { $title = $out[1]; break; } } fclose($file); ?> ]]> </programlisting> </example> </para> <para> You can also write to files on an FTP as long you connect as a user with the correct access rights, and the file doesn't exist already. To connect as a user other than 'anonymous', you need to specify the username (and possibly password) within the URL, such as 'ftp://user:password@ftp.example.com/path/to/file'. (You can use the same sort of syntax to access files via HTTP when they require Basic authentication.) </para> <para> <example> <title>Storing data on a remote server</title> <programlisting role="php"> <![CDATA[ <?php $file = fopen ("ftp://ftp.php.net/incoming/outputfile", "w"); if (!$file) { echo "<p>Unable to open remote file for writing.\n"; exit; } /* Write the data here. */ fputs ($file, "$HTTP_USER_AGENT\n"); fclose ($file); ?> ]]> </programlisting> </example> </para> <para> <note> <para> You might get the idea from the example above to use this technique to write to a remote log, but as mentioned above, you can only write to a new file using the URL fopen() wrappers. To do distributed logging like that, you should take a look at <function>syslog</function>. </para> </note> </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: --> Index: phpdoc/kr/features/connection-handling.xml +++ phpdoc/kr/features/connection-handling.xml <chapter id="features.connection-handling"> <title>Connection handling</title> <note> <para>The following applies to 3.0.7 and later.</para> </note> <para> Internally in PHP a connection status is maintained. There are 3 possible states: <itemizedlist> <listitem><simpara>0 - NORMAL</simpara></listitem> <listitem><simpara>1 - ABORTED</simpara></listitem> <listitem><simpara>2 - TIMEOUT</simpara></listitem> </itemizedlist> </para> <simpara> When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button. If the PHP-imposed time limit (see <function>set_time_limit</function>) is hit, the TIMEOUT state flag is turned on.</simpara> <simpara> You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php3.ini directive as well as through the corresponding php3_ignore_user_abort Apache .conf directive or with the <function>ignore_user_abort</function> function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate. The one exception is if you have registered a shutdown function using <function>register_shutdown_function</function>. With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client diconnect you can use the <function>connection_aborted</function> function. This function will return true if the connection was aborted.</simpara> <simpara> Your script can also be terminated by the built-in script timer. The default timeout is 30 seconds. It can be changed using the max_execution_time php3.ini directive or the corresponding php3_max_execution_time Apache .conf directive as well as with the <function>set_time_limit</function> function. When the timer expires the script will be aborted and as with the above client disconnect case, if a shutdown function has been registered it will be called. Within this shutdown function you can check to see if a timeout caused the shutdown function to be called by calling the <function>connection_timeout</function> function. This function will return true if a timeout caused the shutdown function to be called.</simpara> <simpara> One thing to note is that both the ABORTED and the TIMEOUT states can be active at the same time. This is possible if you tell PHP to ignore user aborts. PHP will still note the fact that a user may have broken the connection, but the script will keep running. If it then hits the time limit it will be aborted and your shutdown function, if any, will be called. At this point you will find that <function>connection_timeout</function> and <function>connection_aborted</function> return true. You can also check both states in a single call by using the <function>connection_status</function>. This function returns a bitfield of the active states. So, if both states are active it would return 3, for example.</simpara> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->