On 12 October 2011 09:19, saeed ahmed <saeed.sas@xxxxxxxxx> wrote: > greeting all, > > As far as I know, there are different ways to write a PHP application: > - CGI, ie. the usual way : some PHP code in web pages, and the PHP > interpreter is loaded each time a PHP page is called > - FastCGI : apparently, the interpreter is loaded at boot time; the > application itself might also be compiled and loaded once > - mod_php : same as FastCGI? > - application server : the application is compiled and loaded once; > the application can either have its own web server, or use a web > server as front end, and only handle its own part > > Any tips much appreciated, thank you. Each of the SAPIs operate in different environments (though I suppose CGI and FastCGI are going to nearly be swappable). CGI - As you rightly say, is loaded on a per-request basis. There is an overhead for every request to get PHP up and running prior to processing the PHP script. Fast-CGI - This requires some cooperation from the server. The server will create a set of PHP instances (separate executable, not running in the same memory space as the server) ready to receive the script. This reduces the overhead that exists with CGI from request loading to server startup/loading. mod_php - I'm on Windows and have not used Apache. But I have used ISAPI. I believe these operate in a similar fashion. In this instance, the PHP interpreter is loaded as a module of the server, just like any other module the server loads. Each PHP script is handled by a separate PHP thread. These threads are NOT separate instances of PHP, and are running within the same address space as the web server. As a consequence, several features/issues exist. Chiefly for me was the persistent database connections. As the same module of code is running all the scripts, a script can (by the use of the appropriate functions) get the database connection remembered between each script. This allows faster connection to the DB for each script. There are issues though. The connection is to the SERVER and not to the DB. The remembered connection is based upon the server, the username and password. If you use multiple databases on the same connection AND use the selectDB functionality, the single remembered DB connection will change DB. If this happens midscript, you could end up in a very strange place. But, if you use qualified naming (database_name.owner.table_name for an MS SQL example), then you will be fine. Just remember select DB is just a shortcut for the connection to use. It isn't part of the connection. Application Server - Don't know. You also have ... CLI - Command line PHP scripting. You must manually invoke PHP with the script name for it to run, though Windows has some useful features to allow you to run a PHP script without having to declare the PHP executable every time. I think the #! line is the Unix equivalent of this feature, but isn't as complete as the Windows mechanism (IMHO) - See http://docs.php.net/manual/en/install.windows.commandline.php for additional details on this. And as of 5.4, there is CLI Server. This is using PHP to run as a listener on the HTTP port and passes requests to a simple, userland, PHP-based routing script which will allow you to respond to PHP requests. See http://docs.php.net/manual/en/features.commandline.webserver.php for more details. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php