Re: cvs: php4 /ext/standard info.c info.h /main main.c
| From: | Zeev Suraski | Date: | Tue, 31 Oct 2000 17:34:23 +0000 |
| Subject: | Re: cvs: php4 /ext/standard info.c info.h /main main.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-2385@lists.php.net to get a copy of this message | ||
We have to think about this generalization. It switched 3 strcmp()'s with a hash lookup. I'd imagine that 3 strcmp()'s, of strings that are likely to be very different from each other (i.e., they'd return a non-zero value quite fast), is considerably quicker than a hash lookup.
With short query strings it doesn't matter all that much, but with a long query string, it can significantly reduce performance, and it's difficult to justify it for that :)
Generally, I like this abstraction. We need to think of a better way to do it.
Perhaps, we should make two tests - an strncmp() for the 4 bytes or so, to see if they're "PHPE", and go on with the hash lookup only if they are.
Zeev
At 19:21 31-10-00, Hartmut Holzgraefe wrote:
-- Zeev Suraski <zeev@zend.com> http://www.zend.com/hholzgra Tue Oct 31 09:21:53 2000 EDTModified files:/php4/main main.c /php4/ext/standard info.c info.hLog: generalization of image handling in phpinfo Index: php4/main/main.c diff -u php4/main/main.c:1.334 php4/main/main.c:1.335--- php4/main/main.c:1.334 Tue Oct 31 04:46:07 2000 +++ php4/main/main.c Tue Oct 31 09:21:52 2000@@ -19,7 +19,7 @@ */ -/* $Id: main.c,v 1.334 2000/10/31 12:46:07 zeev Exp $ */ +/* $Id: main.c,v 1.335 2000/10/31 17:21:52 hholzgra Exp $ */ #include <stdio.h> @@ -259,7 +259,6 @@PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision) PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL) PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)-PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)STD_PHP_INI_ENTRY("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)@@ -875,6 +874,11 @@return FAILURE; }+ if (php_init_info_logos() == FAILURE) { + php_printf("PHP: Unable to initialize info phpinfo logos.\n"); + return FAILURE; + }+zuv.import_use_extension = ".php"; zend_set_utility_values(&zuv); php_startup_sapi_content_types();@@ -936,6 +940,7 @@global_lock_destroy(); zend_shutdown(); php_shutdown_fopen_wrappers(); + php_shutdown_info_logos(); UNREGISTER_INI_ENTRIES(); zend_ini_mshutdown(); shutdown_memory_manager(0, 1);@@ -1133,23 +1138,81 @@ #include "logos.h" +typedef struct _php_info_logo {+ char *mimetype; + int mimelen; + unsigned char *data; + int size;+} php_info_logo; + +HashTable phpinfo_logo_hash; + +PHPAPI int php_register_info_logo(char *logo_string, char *mimetype, unsigned char *data, int size) +{+ php_info_logo *info_logo = (php_info_logo *)malloc(sizeof(php_info_logo));++ if(!info_logo) return FAILURE; + info_logo->mimetype = mimetype; + info_logo->mimelen = strlen(mimetype); + info_logo->data = data; + info_logo->size = size;++ return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), info_logo, sizeof(php_info_logo), NULL);+} + +PHPAPI int php_unregister_info_logos(char *logo_string) +{+ return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string));+} + +int php_init_info_logos(void) +{+ if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) + return FAILURE;++ php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo)); + php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo)); + php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo));++ return SUCCESS;+} + +int php_shutdown_info_logos(void) +{+ zend_hash_destroy(&phpinfo_logo_hash); + return SUCCESS;+} + +#define CONTENT_TYPE_HEADER "Content-Type: " +static int php_info_logos(char *logo_string) +{+ php_info_logo *logo_image; + char *content_header; + int len;+ + if(FAILURE==zend_hash_find(&phpinfo_logo_hash,logo_string,strlen(logo_string),(void **)&logo_image))+ return 0;++ len=strlen(CONTENT_TYPE_HEADER)+logo_image->mimelen; + content_header=malloc(len+1); + if(!content_header) return 0; + strcpy(content_header,CONTENT_TYPE_HEADER); + strcat(content_header,logo_image->mimetype); + sapi_add_header(content_header, len, 1); + free(content_header);++ PHPWRITE(logo_image->data, logo_image->size); + return 1;+} + PHPAPI int php_handle_special_queries(SLS_D PLS_DC) {if (SG(request_info).query_string && SG(request_info).query_string[0]=='=' && PG(expose_php)) { - if (!strcmp(SG(request_info).query_string+1, PHP_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(php_logo, sizeof(php_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, PHP_EGG_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(php_egg_logo, sizeof(php_egg_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, ZEND_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(zend_logo, sizeof(zend_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000")) { + if(php_info_logos(SG(request_info).query_string+1)) + { + return 1; + } else if (!strcmp(SG(request_info).query_string+1, PHP_CREDITS_GUID)) { php_print_credits(PHP_CREDITS_ALL); return 1; }@@ -1287,6 +1350,7 @@zend_indent();} #endif + /* * Local variables: Index: php4/ext/standard/info.c diff -u php4/ext/standard/info.c:1.117 php4/ext/standard/info.c:1.118--- php4/ext/standard/info.c:1.117 Sun Oct 29 03:38:24 2000 +++ php4/ext/standard/info.c Tue Oct 31 09:21:52 2000@@ -17,7 +17,7 @@+----------------------------------------------------------------------+*/ -/* $Id: info.c,v 1.117 2000/10/29 11:38:24 zeev Exp $ */ +/* $Id: info.c,v 1.118 2000/10/31 17:21:52 hholzgra Exp $ */ #include "php.h" #include "php_ini.h" @@ -175,9 +175,9 @@PUTS(SG(request_info).request_uri); } if ((ta->tm_mon==3) && (ta->tm_mday==1)) { - PUTS("?=PHPE9568F36-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\" alt=\"Thies!\"></a>"); + PUTS("?="PHP_EGG_LOGO_GUID"\" border=0 align=\"right\" alt=\"Thies!\"></a>"); } else { - PUTS("?=PHPE9568F34-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\" alt=\"PHP Logo\"></a>"); + PUTS("?="PHP_LOGO_GUID"\" border=0 align=\"right\" alt=\"PHP Logo\"></a>"); } } php_printf("<H1>PHP Version %s</H1>\n", PHP_VERSION);@@ -220,7 +220,7 @@if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } - PUTS("?=PHPE9568F35-D428-11d2-A769-00AA001ACF42\" border=\"0\" align=\"right\" alt=\"Zend logo\"></a>\n"); + PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\"></a>\n"); } php_printf("This program makes use of the Zend scripting language engine:<BR>"); zend_html_puts(zend_version, strlen(zend_version));Index: php4/ext/standard/info.h diff -u php4/ext/standard/info.h:1.17 php4/ext/standard/info.h:1.18--- php4/ext/standard/info.h:1.17 Sun Aug 27 12:42:45 2000 +++ php4/ext/standard/info.h Tue Oct 31 09:21:52 2000@@ -17,7 +17,7 @@+----------------------------------------------------------------------+*/ -/* $Id: info.h,v 1.17 2000/08/27 19:42:45 ssb Exp $ */ +/* $Id: info.h,v 1.18 2000/10/31 17:21:52 hholzgra Exp $ */ #ifndef INFO_H #define INFO_H @@ -44,9 +44,10 @@#define PHP_CREDITS_FULLPAGE (1<<5) #define PHP_CREDITS_ALL 0xFFFFFFFF-#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42" +#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42" #define PHP_EGG_LOGO_GUID "PHPE9568F36-D428-11d2-A769-00AA001ACF42" #define ZEND_LOGO_GUID "PHPE9568F35-D428-11d2-A769-00AA001ACF42"+#define PHP_CREDITS_GUID "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000" PHP_FUNCTION(phpversion); PHP_FUNCTION(phpinfo); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net For additional commands, e-mail: php-cvs-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net