[FAQTS] PHP Knowledge Base Update -- January 26th, 2000

From: Date: Thu, 27 Jan 2000 06:38:16 +0000
Subject: [FAQTS] PHP Knowledge Base Update -- January 26th, 2000
Groups: php.kb 
Request: Send a blank email to php-kb+get-43@lists.php.net to get a copy of this message
If you know the answer to any of the unanswered questions below please jump in and help. You just need to click the "Edit this Entry" link on the appropriate page. http://php.faqts.com Cheers, Nathan ## Unanswered Questions ######################################## ------------------------------------------------------------- when uploading binary files, some bytes are become corrupted, but file size isnt changing, why ? http://www.faqts.com/knowledge-base/view.phtml/aid/724 ------------------------------------------------------------- Dmitry Jo ------------------------------------------------------------- Is there a way of forcing PHP to require explicit variable declaration, as in PERL with "use strict" ? http://www.faqts.com/knowledge-base/view.phtml/aid/725 ------------------------------------------------------------- b linc ------------------------------------------------------------- Dear All, I try to configure PHP3 but it keeps complaining about a missing file /usr/local/apache/bin/apxs. Where can I get this file??? Please Help! http://www.faqts.com/knowledge-base/view.phtml/aid/726 ------------------------------------------------------------- Ronald Tolboom ------------------------------------------------------------- Can I create symbolic links using PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/727 ------------------------------------------------------------- Elrond Sheppard ## New Entries ################################################# ------------------------------------------------------------- How do I setup so mail() will work under windows? http://www.faqts.com/knowledge-base/view.phtml/aid/715 ------------------------------------------------------------- Nathan Wallace Phil Driscoll No problem. Just set: SMTP = the.mail.server.name ;for win32 only sendmail_from = you@wherever.com ;for win32 only in your php.ini file and then call the mail function as described in the manual. ------------------------------------------------------------- How can I remove profanity from a string? How can I censor selected words from a string? http://www.faqts.com/knowledge-base/view.phtml/aid/716 ------------------------------------------------------------- Nathan Wallace Richard Lynch Try using this function: <?php function sanitize($text){ //Any George Carlin or FCC fans remember the whole "deadly 7"list? static $naughty = array('shit', 'fuck'); while (list(,$bad) = each($naughty)){ $text = str_replace($bad, make_string('*', strlen($bad)), $text); } return $text; } ?> Note: Sure wish there was a stri_replace... And make_string is a PHP4 thing, so you may need to roll your own. ------------------------------------------------------------- Can I change NT registry settings from PHP / Apache? http://www.faqts.com/knowledge-base/view.phtml/aid/728 ------------------------------------------------------------- Nathan Wallace Richard Lynch Scary! Okay, presumably you know what you're doing to edit the settings... Assuming the user that Apache is logged in as is capable of executing and editing whatever needs to be executed and edited, you could use exec() to run command-line registry-editing programs... ------------------------------------------------------------- Why do I get this error '403.1 Forbidden: Execute Access Forbidden' with PWS? http://www.faqts.com/knowledge-base/view.phtml/aid/729 ------------------------------------------------------------- Nathan Wallace yorke, The Eyrie This error can be caused if you try to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed. You need to set the execute flag on the directory under PWS. ------------------------------------------------------------- How can I get the class name of an object? http://www.faqts.com/knowledge-base/view.phtml/aid/730 ------------------------------------------------------------- Nathan Wallace Richard Lynch, Gregor Welters PHP4/Zend is supposed to have such a function, I think... Otherwise, give the class a property named "classname" and fill it with the classname. ------------------------------------------------------------- How do I setup PHP on Solaris 7? http://www.faqts.com/knowledge-base/view.phtml/aid/731 ------------------------------------------------------------- Nathan Wallace Chad Cunningham I have it on several Solaris7 machines. I've used gcc and Sun's workshop C compiler. I'd stick with gcc, it's a bit friendlier. Also make sure you don't use any of the GNU linking stuff. Basically I use gcc to compile, but have /usr/ccs/bin/ before any of the GNU stuff on the path. If you use gnu's ld, you're most likely going to have problems. We were getting a lot of frequent core dumps with php/apache until we realized gnu's ld had some issues with building php as a loadable module. ------------------------------------------------------------- How can I get the name of the user logged in using HTTP authentication? What is the REMOTE_USER apache variable for? http://www.faqts.com/knowledge-base/view.phtml/aid/733 ------------------------------------------------------------- Nathan Wallace Brent Bearden, Richard Lynch REMOTE_USER is the name of the user currently logged in using HTTP authentication. It is available in PHP as the variable: $REMOTE_USER $REMOTE_USER is set by Apache, or not, depending on the whim of the configuration in httpd.conf ------------------------------------------------------------- Why does PHP_SELF contain php.exe? Why do my URL's contain php.exe? http://www.faqts.com/knowledge-base/view.phtml/aid/734 ------------------------------------------------------------- Nathan Wallace Richard Lynch, Robin Gibson On Windows, when you give any php3 url in the browser, say: http://localhost/hello.php3 and the php3 script calls itself in the script from a form submit, i.e: <form action=<?php echo $PHP_SELF ?> then when the script runs the second time, the url changes to: http://localhost/php3/php.exe/hello.php3 It seems goofy, but that's how Apache actually does the Action stuff: It maps it into a big long URL that has php.exe in it and the script you want. So your action definition in the httpd.conf probably looks like this: Action application/x-httpd-php3 "/php3/php.exe" You can just use ACTION=hello.php3 instead of $PHP_SELF if you prefer. There is a simple fix. Just add this line to the beginning of any page using the $PHP_SELF global: $PHP_SELF = str_replace($SCRIPT_NAME, "", $PHP_SELF); $SCRIPT_NAME contains (e.g..) "/php3/php.exe" - the path to the PHP executable. The fix yanks that out of $PHP_SELF. ------------------------------------------------------------- What is the difference between standard function arguments and passing by reference? When should I pass function arguments by reference? http://www.faqts.com/knowledge-base/view.phtml/aid/736 ------------------------------------------------------------- Nathan Wallace Richard Lynch Passing by reference is good for two things: 1. Avoid passing a *HUGE* amount of data into a function which must copy it all and then throw away that copy when it is done. PHP3 does this (and only this) using function (&$x) 2. Allow you to *alter* the actual value of a variable: <?php function show($x){ $x = 3; echo "In-Show: $x<BR>\n"; } function munge(&$x){ $x = 4; echo "In-Munge: $x<BR>\n"; } $y = 2; echo "Pre-Show: $y<BR>\n"; show($y); echo "Post-Show: $y<BR>\n"; echo "Pre-Munge: $y<BR>\n"; munge($y); echo "Post-Munge: $y<BR>\n"; ?> Assuming PHP4 behaves like C, this will output: Pre-Show: 2 In-Show: 3 Post-Show: 2 Pre-Munge: 2 In-Munge: 4 Post-Munge: 4 NOTE THAT LAST LINE!!! munge actually *changed* the value of $y Disclaimer: I probably got the syntax wrong. But the point should still be valid... ------------------------------------------------------------- Do I have to close database connections at the end of my scripts? http://www.faqts.com/knowledge-base/view.phtml/aid/723 ------------------------------------------------------------- Nathan Wallace, Mike S. Krischker No. If you are using persistent connections they won't be closed, even if you do call the close function for your database. They remain connected until the Apache process is killed. If you are not using persistent connections then the connection will be closed automatically by PHP at the end of script execution. Having said all that, it's probably good programming technique / style to close your connections. ## Edited Entries ############################################## ------------------------------------------------------------- What does an ampersand (&) before a function parameter do? How can I pass a variable by reference to a function? http://www.faqts.com/knowledge-base/view.phtml/aid/134 ------------------------------------------------------------- Nathan Wallace Chad Cunningham It passes the variable by reference, which is to say that rather than passing the function the contents of the variable, it passes the memory address of the variable instead. See function -> Passing by Reference -> Arguments in: http://www.php.net/manual/control-structures.php3 ------------------------------------------------------------- Can I close a persistent connection? Are persistent connections ever closed? What causes the error 'MySQL Connection Failed: Too many connections' ? http://www.faqts.com/knowledge-base/view.phtml/aid/230 ------------------------------------------------------------- Nathan Wallace Paul DuBois, Chad Cunningham, Nathan Wallace You cannot close a persistent connection in PHP. Closing a persistent link in a script defeats the purpose of having a persistent link. If you want to close it, just open the connection with mysql_connect() so that you can close it. One persistent connection is established for each Apache child process the first time that the database connect is called in the lifetime of that process. For more info about persistent connections see: http://www.php.net/manual/features.persistent-connections.php3 In Apache the child process only serves a certain number of requests before it is killed and a new child started. When the process is killed the connection to the database that it held will be closed. Hence, your database connections do have a finite lifetime. Here is an excerpt from: http://www.apache.org/docs/mod/core.html#maxrequestsperchild The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire. Setting MaxRequestsPerChild to a non-zero limit has two beneficial effects: * it limits the amount of memory that process can consume by (accidental) memory leakage; * by giving processes a finite lifetime, it helps reduce the number of processes when the server load reduces. If you run an extremely high traffic site which does a lot of database requests then you may need to be careful. Although Apache/PHP has lost the connection to the database and no longer uses it, MySQL does not necessary close the connection. Your timeout settings for httpd processes and MySQL persistent connections need to be configured properly. The time the connection stays open relies on mysql settings. If you do: mysqladmin variables you will see something like this: +----------------------------+---------------------------------------+ | Variable_name | Value | +----------------------------+---------------------------------------+ | back_log | 5 | | connect_timeout | 5 |

« previous php.kb (#43) next »