Page 98 - Open Soource Technologies 304.indd
P. 98

Web Technologies-I



                   Notes         ini_get, ini_restore, ini_set, localeconv, parse_ini_file, php_logo_guid, php_sapi_name, php_
                                 uname,phpcredits, phpinfo, phpversion, putenv, set_magic_quotes_runtime, set_time_limit,
                                 version_compare, zend_logo_guid, zend_version
                                 Program execution

                                 escapeshellarg , escapeshellcmd, exec, passthru, putenv, shell_exec, sleep, system, usleep
                                 Strings
                                 addcslashes, addslashes, base64_decode, base64_encode, chop, chr, chunk_split, convert_cyr_string,
                                 count_chars, crypt, echo, ereg,ereg_replace, eregi, eregi_replace, explode, get_html_translation_
                                 table, get_meta_tags, hebrev, hebrevc, highlight_string, htmlentities,htmlspecialchars, implode,
                                 iptcparse, join, levenshtein, localeconv, ltrim, md5, metaphone, nl2br, number_format, ord,
                                 parse_str, parse_url,print, printf, quoted_printable_decode, quotemeta, rtrim, setlocale, similar_
                                 text, soundex, split, spliti, sprintf, sql_regcase, sscanf,str_pad, str_repeat, str_replace strcasecmp,
                                 strchr, strcmp, strcoll, strcspn, strip_tags, stripcslashes, stristr, strlen, strnatcasecmp,strnatcmp,
                                 strncasecmp, strncmp, strpos, strrchr, strrev, strrpos, strspn, strstr, strtok, strtolower, strtoupper,
                                 strtr, substr,substr_count, substr_replace, trim, ucfirst, ucwords, vprintf, vsprintf, wordwrap
                                 Type functions
                                 doubleval, get_resource_type, gettype, intval, is_array, is_bool, is_double, is_float, is_int, is_
                                 integer, is_long, is_null, is_numeric,is_object, is_real, is_resource, is_scalar, is_string, settype, strval
                                 URLs

                                 base64_decode, base64_encode, parse_url, rawurldecode, rawurlencode, urldecode, urlencode
                                 Variable functions
                                 compact, empty, extract, get_defined_constants, get_defined_vars, import_request_variables,
                                 isset, list, print_r, putenv, serialize,uniqid, unserialize, unset, var_dump




                                              Is PHP Embarrassingly Slower than Java?



                                      P2C is a small library that provides IP to country resolution. It uses the free ip-to-country
                                      database. IP2C takes the database CSV file that is about 4mb and converts it into a ~600kb
                                   Ibinary format and provides PHP and Java frontend to query the database.
                                   The library is great, easy to convert an IP to a country and when using the country flags from
                                   its side project you could spice up your statistics with the country information. This is a lot
                                   faster than using reverse DNS lookup.

                                   The problem: The PHP implementation is a lot slower. Embarrassingly slower. Without any
                                   caching the Java version is able to do ~6000 queries per second. The PHP counterpart can push
                                   through ~850 queries. The implementations are the same. The stats provided by the author
                                   of the library are 8000 vs 1200. So about the same as my measurements.
                                   I like PHP, I do not use it that much anymore but I still care when I see such embarrassing
                                   numbers. I took the implementation and started profiling it. Spent the night running different
                                   tests and trying to optimize.
                                   General outline of the algorithm is as follows. We take the dotted string IP and convert it to an
                                   IPv4 Internet network address (e.g. 69.55.232.153 becomes 1161291929). The DB holds sorted
                                                                                                      Contd...


        92                                LOVELY PROFESSIONAL UNIVERSITY
   93   94   95   96   97   98   99   100   101   102   103