Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30929 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55571 invoked by uid 1010); 14 Jul 2007 15:13:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 55556 invoked from network); 14 Jul 2007 15:13:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2007 15:13:08 -0000 Authentication-Results: pb1.pair.com header.from=tijnema@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=tijnema@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.132.243 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: tijnema@gmail.com X-Host-Fingerprint: 209.85.132.243 an-out-0708.google.com Received: from [209.85.132.243] ([209.85.132.243:12555] helo=an-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/46-09288-208E8964 for ; Sat, 14 Jul 2007 11:13:08 -0400 Received: by an-out-0708.google.com with SMTP id c18so150309anc for ; Sat, 14 Jul 2007 08:13:04 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=t2/9dcF/PG9Il2ngk14Qar8MM9ZJU5chPI/OR5I9Q3BT3tfFa1TzdWzaaPJt83GOIg1WhXgCSLLLrhhRZ5TRsHNmppdZenuRye2Id2dYa3pLlmm69UDUocqO17yf4/CMcLx8bv5ah7EoP4eJs2A1sN5RGXFQY6DNWF0HzLDfjTw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=etplWQFA9YO9wVXYRSwXcdBVqjn3uanP67PVhxnx9wM1qdI/J0M0tPD21miMUxas7+ilPO2TyevYaiVBqHoc7rmiPSDgxo0QiXnABjv5YzahqCgSeojW4vcTZG0HaeroBYk+7yAf+MSUkVnm1wepMUuTU+WqDs+CtSpQfmgD3nY= Received: by 10.100.10.20 with SMTP id 20mr1450636anj.1184425984137; Sat, 14 Jul 2007 08:13:04 -0700 (PDT) Received: by 10.100.33.17 with HTTP; Sat, 14 Jul 2007 08:13:03 -0700 (PDT) Message-ID: Date: Sat, 14 Jul 2007 17:13:03 +0200 To: "Stanislav Malyshev" Cc: "PHP Developers Mailing List" In-Reply-To: <469877B6.8010307@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <469877B6.8010307@zend.com> Subject: Re: [PHP-DEV] Apache handler with Multiple PHP versions From: tijnema@gmail.com (Tijnema) On 7/14/07, Stanislav Malyshev wrote: > > The Apache2handler SAPI should be loaded first, and read the very > > first line of the PHP script to determine if a version is specified > > there. If not, the handler needs to load its default PHP version. If > > it is specified, it should try to load that version, and if it > > couldn't find or load that version, fall back to the default version > > and issue a warning. > > This means the engines would have to init/shutdown on each request, > which makes it as bad as CGI. Is that really a big problem? And isn't that what Apache currently does? As I said before, I don't know a lot about PHP core/ Apache2handler SAPI, But I expected Apache to load PHP on each request. And what if I just load and init all PHP versions at once with different handles? (See example code at the bottom of this message) > Why not just go FastCGI? You can use > extensions like .php4 and .php5. > -- > Stanislav Malyshev, Zend Software Architect It's not just for my personal server, I just load different PHP versions by updating a symlink (libphp.so -->libphp4.so, libphp5.so or libphp5-2-1.so), and restarting Apache. I talked to my webmaster of my Shared host, and he said: "I don't see a reason to use FastCGI with different extensions, this will probably lead to problems with unexperienced users on this server. If your idea shows no security issues, performance issues or difficult configuration settings, we will use it to support more versions of PHP." So, that confirms what I was thinking, but other webmasters might think different about it. Tijnema The code for loading and starting up different PHP versions at once: --------------------php4.c-------------------- int *parse_php_code(char *file) { return 4; } int php_startup() { return 1; } --------------------/php4.c-------------------- --------------------php5.c-------------------- int *parse_php_code(char *file) { return 5; } int php_startup() { return 1; } --------------------/php5.c-------------------- --------------------php6.c-------------------- int *parse_php_code(char *file) { return 6; } int php_startup() { return 1; } --------------------/php6.c-------------------- --------------------loader.c-------------------- #include #include int main(int argc, char *argv[]) { void *handle4, *handle5, *handle6; char *error; int *(*parse_code4)(char *); int *(*startup4); int *(*parse_code5)(char *); int *(*startup5); int *(*parse_code6)(char *); int *(*startup6); FILE * fp; char *ver; char *buffer; if(argc != 2) { fprintf(stderr, "Syntax: %s \n", argv[0]); exit(1); } handle4 = dlopen("./libphp4.so", RTLD_LAZY); handle5 = dlopen("./libphp5.so", RTLD_LAZY); handle6 = dlopen("./libphp6.so", RTLD_LAZY); if(!handle4) { fprintf(stderr, "%s\n", dlerror()); exit(1); } if(!handle5) { fprintf(stderr, "%s\n", dlerror()); exit(1); } if(!handle6) { fprintf(stderr, "%s\n", dlerror()); exit(1); } startup4 = dlsym(handle4, "php_startup"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 4, error); exit(1); } startup5 = dlsym(handle5, "php_startup"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 5, error); exit(1); } startup6 = dlsym(handle6, "php_startup"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 6, error); exit(1); } if(!(*startup4)) { fprintf(stderr, "Failed to startup PHP %d\n", 4); exit(1); } if(!(*startup5)) { fprintf(stderr, "Failed to startup PHP %d\n", 5); exit(1); } if(!(*startup6)) { fprintf(stderr, "Failed to startup PHP %d\n", 6); exit(1); } parse_code4 = dlsym(handle4, "parse_php_code"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 4, error); exit(1); } parse_code5 = dlsym(handle5, "parse_php_code"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 5, error); exit(1); } parse_code6 = dlsym(handle6, "parse_php_code"); if((error = dlerror()) != NULL) { fprintf (stderr, "PHP%d: %s\n", 6, error); exit(1); } fp = fopen(argv[1], "r"); if(fp == NULL) { fprintf (stderr, "Error opening php file %s\n", argv[1]); exit(1); } buffer = (char *) malloc(13); ver = (char *) malloc(2); fread(buffer,1,12,fp); if(strcmp(buffer," --------------------/test4.php-------------------- --------------------test5.php-------------------- --------------------/test5.php-------------------- --------------------test6.php-------------------- --------------------/test6.php-------------------- Compiled with: gcc -shared -fPIC php4.c -o libphp4.so gcc -shared -fPIC php5.c -o libphp5.so gcc -shared -fPIC php6.c -o libphp6.so gcc -rdynamic -o loader loader.c -ldl Test results: ./loader ./test4.php (Outputs 4) ./loader ./test5.php (Outputs 5) ./loader ./test6.php (Outputs 6)