[FAQTS] PHP Knowledge Base Update -- May 18th, 2000

From: Date: Thu, 18 May 2000 12:41:54 +0000
Subject: [FAQTS] PHP Knowledge Base Update -- May 18th, 2000
Groups: php.kb 
Request: Send a blank email to php-kb+get-48@lists.php.net to get a copy of this message
Thanks to everyone who is contributing answers and improvements. Keep them coming! :) http://php.faqts.com cheers, Nathan ## Unanswered Questions ######################################## ------------------------------------------------------------- How can I find out what the date of the last monday was without year/month concerns? http://www.faqts.com/knowledge-base/view.phtml/aid/2988 ------------------------------------------------------------- Dave Mitchell ------------------------------------------------------------- Scalability of PHP. Is it possible to scale a PHP system to several computer through loadbalancing or similar??? HOW?? http://www.faqts.com/knowledge-base/view.phtml/aid/3013 ------------------------------------------------------------- Christian Bjørnbak ------------------------------------------------------------- How do you get Xitami & php4 to work together with xitami aliases? http://www.faqts.com/knowledge-base/view.phtml/aid/2986 ------------------------------------------------------------- Mike Lavengood ------------------------------------------------------------- Help, how to I get php4 to build on HPUX 10.20 with gcc 2.7.2 - the *time_r functions bomb it out http://www.faqts.com/knowledge-base/view.phtml/aid/2991 ------------------------------------------------------------- Jim Sauber ------------------------------------------------------------- Why can't I run php from command line? http://www.faqts.com/knowledge-base/view.phtml/aid/1746 ------------------------------------------------------------- Charles Chan, Henrik Hansen ------------------------------------------------------------- can php update a textfile that i can use for a flash movie? http://www.faqts.com/knowledge-base/view.phtml/aid/3025 ------------------------------------------------------------- philipp schiedl ------------------------------------------------------------- Windows 98, PHP4RC2 - mail function does not work. Anyway what happened to the php3_*.dll's? Will there be a PHP4 version? http://www.faqts.com/knowledge-base/view.phtml/aid/2992 ------------------------------------------------------------- Atanas Kebedjiev ## New Entries ################################################# ------------------------------------------------------------- I'm looking for doc's on php_admin_value and php_admin_flag. Any idea where I could find them? I have looked at zend.com and php.net with no luck. http://www.faqts.com/knowledge-base/view.phtml/aid/2990 ------------------------------------------------------------- Thomas J. Mackie III, Nick Vasilogianis taken from "Professional PHP Programming" php_admin_value: name value - This sets of admin related variable specified by name to value. Administrative configuration settings can only be set from within th emain Apache configuration file(httpd.conf), and not from the .htaccess files. php_admin_flag: name on|off - This is used to set to either on or off any admin-related boolean configuration option specified by the name. ------------------------------------------------------------- Can I use PHP with Oracle on Windows? How do I enable the Oracle functions with PHP on Windows? http://www.faqts.com/knowledge-base/view.phtml/aid/3010 ------------------------------------------------------------- Nathan Wallace Gregor Zurowski, Zack Beatty Yes, it does have Oracle 8 support. Include the php3_oci80.dll in your php.ini file (via extentsion=php3_oci80.dll). Then you can use all OCI function described in the manual. Don't forget to install Net8 on your machine. Here are the "php3_oci73.dll" functions that you are using (i.e. ora_logon): http://www.php.net/manual/ref.oracle.php3 Here are the "php3_oci80.dll" functions you should be using (i.e. OCIlogon): http://www.php.net/manual/ref.oci8.php3 You need to change all of the old Oracle functions to the new ones in order to use the new oci80.dll. ------------------------------------------------------------- Why do I keep getting a "permission denied" error for Postgres queries? How can I give a user permissions in Postgres? http://www.faqts.com/knowledge-base/view.phtml/aid/3026 ------------------------------------------------------------- Nathan Wallace Doug Semig This answer assumes that you want the Postgres user "nobody" to have permissions. What you have to do now is GRANT permissions for the user "nobody" to do things with your tables. Log in to psql as the owner of the database and type in: GRANT SELECT, INSERT, DELETE, UPDATE ON tablename TO nobody; Type that line in for each table your web application will need to run select, insert, delete, and update queries on. Note that if you don't want to grant the "nobody" user the ability to delete or update, then you'd leave those out of the GRANT statement. ------------------------------------------------------------- What are the advantages of storing session data in a database and not a file? Should I use database session handling or file session handling? http://www.faqts.com/knowledge-base/view.phtml/aid/3027 ------------------------------------------------------------- Nathan Wallace Sascha Schumann, Richard Lynch You need a database in the central-database, multiple-front-web-servers scenario. If you have only one web server, files are good enough. I'm thinking that once you have a database connection open, an extra query to get their session info is probably less than opening / read / closing a file... If you're not already using a database, a straight file-system will be faster, probably. Caveats: You really should spend time building samples and "fake" data and pounding on a server to see where the bottle-neck is going to be, and fixing that bottle-neck to get the most bang for the buck, but it shouldn't be too hard to do a side-by-side comparison of file versus database session-handling with sample date for your system. The file-system solution won't scale to multi-tier architecture too well. The database system will, assuming you can scale your database in the first place. ------------------------------------------------------------- How can I create a color a shade darker than a given hex value? http://www.faqts.com/knowledge-base/view.phtml/aid/3028 ------------------------------------------------------------- Nathan Wallace Phil Driscoll Extract the individual colour components using & and shifts, multiply by a suitable factor (eg 0.9) then recombine $Red=intval((($Color & 0xFF0000)>>16)*0.9); $Green=intval((($Color & 0xFF00)>>8)*0.9); $Blue=intval(($Color & 0xFF)*0.9); $Color=($Red<<16)+($Green<<8)+$Blue; Someone who understands operator precidence better than I do could probably lose a few brackets. There's also probably some cute trick which does the entire job in one shot. ------------------------------------------------------------- How can I access a secure database server from a PHP web server? How should I setup my web server network so the database server is not accessible to people? http://www.faqts.com/knowledge-base/view.phtml/aid/3029 ------------------------------------------------------------- Nathan Wallace Rick Widmer You establish a second, separate network between the web servers and the database server. As long as the web servers don't forward packets the two networks can never communicate, yet the web servers can access both the Internet and the database server. The key to security is not so much locking down the ports on the database server as making sure the web servers do not forward packets to/from the Internet. I'm not saying don't lock down unneeded ports, that is common sense, just pointing out the key is not forwarding packets thru the web servers. How to set it up... Database Server: This machine is fairly normal and has only one network card. Shut off everything but the database server. No sendmail, httpd, etc. Disable anything you don't _need_ in inetd.conf. If you don't need any inetd services don't start the daemon. Pick an IP address from RFC1918 address space. (10.x.x.x, 192.168.x.x and one other block I don't remember.) Add this address to your /etc/hosts files or DNS so web server(s) can find the database server. The Database Network: Connect the database machine to a new hub or switch that is NOT connected to the Internet. If there is only one web server you can use a crossover cable. Connect the second network card in each web server to the database network hub. Make SURE it connects to nothing but web servers that need access to the hidden database server. One possible exception would be a backup server. (As in a box with a tape drive.) It would be able to see the web servers and the database, but not the Internet, or your news and mail servers. Web server(s): Add a second network card. Pick an RFC1918 address in the same subnet as the database server. Connect it to the database network. Make sure IP forwarding is OFF, so the machine will not route packets from one interface to the other. THIS IS VERY IMPORTANT!!! I compile static kernels with IP Forwarding disabled for my servers. Make sure the database server is referenced in /etc/hosts or DNS so you can list it by name in the hostname parameter of all your scripts. Start pointing your scripts at the hidden database server. ------------------------------------------------------------- Why are there 2 functions : OCIParse and OCIExecute? http://www.faqts.com/knowledge-base/view.phtml/aid/3030 ------------------------------------------------------------- Nathan Wallace Arnaud Megret It enables to bind in and out PHP variables with the query. It is possible to call OCIEXecute() multiple times after one call to OCIParse. So you could bind variables to the SQL query, and executes it several times changing the values of the binded variables before each call to OCIExecute. Thus improving speed... ## Edited Entries ############################################## ------------------------------------------------------------- How do you install OpenLDAP with PHP and Apache? http://www.faqts.com/knowledge-base/view.phtml/aid/808 ------------------------------------------------------------- Joshua Starr, Henrik Hansen PHP manual You should compile PHP with the following configure flag: --with-ldap=DIR Where DIR is where LDAP is installed. ------------------------------------------------------------- Does PHP work on an AIX platform? http://www.faqts.com/knowledge-base/view.phtml/aid/1346 ------------------------------------------------------------- Jimmy A Blanco, Henrik Hansen Yes the PHP source code should work on most unix platforms, including AIX ------------------------------------------------------------- how can i compile php with mcrypt correctly? i tried, but failed. http://www.faqts.com/knowledge-base/view.phtml/aid/1336 ------------------------------------------------------------- lily xie, Henrik Hansen, Nathan Wallace PHP Manual Compile PHP with the following configure flag: --with-mcrypt Which includes support for the mcrypt library. See the mcrypt documentation for more information[1]. If you use the optional DIR argument, PHP will look for mcrypt.h in DIR/include. 1. The documentations is here: http://www.php.net/distributions/bigmanual.html#REF.MCRYPT ------------------------------------------------------------- On which Operating systems is PHP (successfully) running? http://www.faqts.com/knowledge-base/view.phtml/aid/2030 ------------------------------------------------------------- Wolfgang Schaefer, Henrik Hansen PHP 3.0 maillinglist php will run at least on the following platforms: Linux, Unix, Windows NT, Macintosh, VMS and OS/2. ------------------------------------------------------------- Is it possible to use dl("sharedlib.so") under linux, similar to the way it used under Windows? http://www.faqts.com/knowledge-base/view.phtml/aid/2096 ------------------------------------------------------------- Scott Brause, Henrik Hansen Yes it is, for example if you want to load the mysql functions do: dl(mysql.so); ------------------------------------------------------------- For maximum performance, should I use global vars when calling my own function, or should I pass the required vars as args? http://www.faqts.com/knowledge-base/view.phtml/aid/2165 ------------------------------------------------------------- Steven Campbell, Marek Narkiewicz www.php.net/manual As I see it the most efficient and thus faster way would be to declare the variables global within the function. The tidiest code would result from passing the variables to the function. Therefore a good compromise would be to pass the variables to the function by reference rather than by value. function foo($arg){ echo $arg; } $word = "sheep"; foo(&$word); this will echo "sheep" This is more efficient as the variable in the function is only a pointer to the variable outside the function and can help you to maintain good code. hth. ------------------------------------------------------------- How do I install php3, mysql and apache on windows95? http://www.faqts.com/knowledge-base/view.phtml/aid/2354 ------------------------------------------------------------- Preeti Sikri, Henrik Hansen Look at this page which has docomentation on how to install php/mysql/etc on windows platforms http://www.umesd.k12.or.us/php/win32install.html ------------------------------------------------------------- What should I do to make my php to work with MySQL ? http://www.faqts.com/knowledge-base/view.phtml/aid/2520 ------------------------------------------------------------- Antony Lee, Henrik Hansen PHP manual Compile PHP with: --with-mysql=DIR Which enables MySQL support. The parameter to this option is the MySQL install directory and defaults to /usr/local. This is the default installation directory of the MySQL distribution. Bofore doing this you should have a working mysql server installed on your system. ------------------------------------------------------------- Is there a port of PHP for OpenVMS? http://www.faqts.com/knowledge-base/view.phtml/aid/2863 ------------------------------------------------------------- Istvan Banfi, Henrik Hansen Yes the php source should compile under vms platforms. ------------------------------------------------------------- What is PHP? http://www.faqts.com/knowledge-base/view.phtml/aid/2881 ------------------------------------------------------------- Nathan Wallace, Tyler Bannister Andrei Zmievski PHP is a general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax is similar to C, Java, and Perl. PHP runs on many different platforms and can be used as a standalone executable as well as under many web servers. It has excellent support for databases, various Internet protocols, and general data manipulation. PHP can be extended through its powerful API to include additional functionality. ------------------------------------------------------------- How can I add/write to an existing file? http://www.faqts.com/knowledge-base/view.phtml/aid/2650 ------------------------------------------------------------- Henrik Jönsson, Peter Morrissette, Colin Viebrock, Nathan Wallace http://www.php.net/manual/function.fopen.php3 I generally do this (perhaps not the best way of doing it, but it works!): Read the file you want to change into an array (or string). Then add the changes to it accordingly (ofcourse this means you have to know where to add it) then write the file again. Ex. (to add at the end of the file); // set where the file is located $file_path = "filepath & filename"; // start reading in the file into the array $fileopen = @fopen($file_path, "r"); if (!$fileopen) { echo "Can't open file"; } for ($i=0; $buffer = fgets($fileopen, 16192); $i++) { $arr_file[$i] = $buffer; } fclose($fileopen); // this is what you want to add $str_toadd = "This i want to add"; // write the file $fileopen = @fopen($file_path, "w"); for ($i=0; $i < sizeof($arr_file); $i++) { fwrite($fileopen, $arr_file[$i], 16192); } fwrite($fileopen, $str_toadd, 16192); fclose($fileopen); As said earlier, probably a bit messy, but I've had no worries using it. -------------- If you are simply appending to the end of an existing file, then you should just use the append switch to fopen(): <? $fp = fopen($filename, "a"); fwrite($fp, $newdata); fclose($fp); ?> Just a *bit* cleaner. :)

« previous php.kb (#48) next »