php4 is extremelly fast!

From: Date: Wed, 02 Jun 1999 17:46:18 +0000
Subject: php4 is extremelly fast!
Groups: php.version4 
Request: Send a blank email to php-version4+get-1250@lists.php.net to get a copy of this message
i promised a report about ereg() causing segfault and 8mb big core file. i guess it was connected with exec() which is now corrected and my script is working just fine (as it should since it is working very good with php3). i made a few test running that script through php3 and php4 and the result is very very surprising: php4 is 18-20 times faster than php3! the script (coments are in croatian lang, please forgive me) is included below. how i performed the tests: i have a big txt file (52000 lines - 2.15mb) which is just a part of a very big Folio database, exported as text. after some testing i'll employ the script on all 6.000.000 lines of DB. exec(/bin/cat file) reads the file into an array. every line of the file is checked against a few ereg()'s and about 20 directories and about 25 html files in each directory are created. script calls mtime() before and after the file manipulation. php3 processes the file in 220-240 seconds. php4 processes the file in 12-13 seconds. this script is the first 'serious' job i've done with php3 and it is acctually confused and clumpy but it's working just what it should. my configuration: P166MMX 128MB RAM HDD (on which the process is running) Quantum Fireball 1.28Gb RedHat5.2 gcc 2.7.2.3 glibc 2.0.7 kernel 2.2.9 hmmmm... anything else that would be interesting? here's the script. ---------------------------------------------- #!/opt2/davor/php4/bin/php4 -q <?php /* 1999/24/04/14/50 - v0.0.3 - ne ispisuje više naslov sljedećeg chaptera na dnu zadnjeg text_broj fajla prethodnog chaptera 1999/24/04/14/15 - v0.0.2 - ispisuje Chapter 1 : TEXT 1 (i sl) na početku text stranice 1999/24/04/14/00 - v0.0.1 - prva verzija koja generira smislene stranice */ // Uzmi argumente i podijeli ih u varijable // Ako nema argumentata, ispiši uputstvo if ($argc == 1) { echo "Upotreba: $argv[0] ime_fajla\n"; exit(); } $file = $argv[1]; set_time_limit(0); // bez ograničenja trajanja $htmlhead = "<html>\n<head>\n<title>Krsna</title>\n</head>\n<body bgcolor=\"#ffffff\">\n"; $htmlfoot = "</body>\n</html>"; echo "Obrađujem file $file\n"; echo "Učitavam!\n"; function mtime() { $time = explode(" ", microtime()); $micro = doubleval($time[0]); $sec = doubleval($time[1]); return $micro + $sec; } $pwd = "/tmp/krisna/temp/"; $start = mtime(); exec ("/bin/cat $file", $polje); $end = mtime(); $total = $end - $start; echo ("$total sekundi.\n"); $br_redova = count($polje); echo "Učitano $br_redova linija.\n"; echo "Počinjem s obradom.\n"; echo "Pravim zajednički TOC.\n"; $global_toc_html = $pwd . "toc.html"; //zajednički TOC touch ("$global_toc_html"); echo "Napravljen.\n"; echo "Stavljam standardne HTML stvari u toc.html\n"; $fp_global_toc = fopen ("$global_toc_html", a); fputs ($fp_global_toc, "$htmlhead\n<ol>"); fclose ($fp_global_toc); $start = mtime(); for ($i=1500; $i<$br_redova; $i++) { $interni_brojac = $i % 500; // za obavještavanje o napretku if ($interni_brojac == 0) { echo "Obrađeno $i redova.\n"; }; if ( ereg( "^Bg [0-9]{1,}: ", $polje[$i])) { //našao Bg 1: naslov - reset echo "Našao $polje[$i]\n"; continue; /* if($fp_text) { fputs($fp_text, $htmlfoot); fclose($fp_text); };*/ /* if ($fp_chapter_toc) { fclose ($fp_chapter_toc); echo ("Našao već otvoreni chapter_toc. Preskačem.\n"); continue; }; */ // zatvori chapter_toc ako postoji (znači, drugi ili viši chapter) }; if ( ereg( "^Chapter [0-9]{1,}$", $polje[$i])) {//našao Chapter echo "Našao $polje[$i] u $i. redu.\n"; //obavijest $chapter_naslov_br = $polje[$i]; // zapamti "Chapter br" $chapter_naslov = $polje[$i+2]; // uzmi naslov chaptera printf ("%s\n", $chapter_naslov); // i ispiši ga $chapter = ereg_replace(" ", "_", $polje[$i]); // zamijeni space za _ $chapter_dir = $pwd . $chapter; // dodaj path komponentu - direktorij. echo "Pravim direktorij $chapter_dir.\n"; $mkdir_temp = mkdir ("$chapter_dir", 0755); if ($mkdir_temp == FALSE) { echo "Greška! Nisam napravio direktorij $chapter_dir.\n"; exit(); } else { echo "Direktorij $chapter_dir napravljen.\n"; }; $chapter_toc_file = $chapter_dir . "/" . $chapter . "_toc.html"; // pravi TOC za taj chapter Chapter_1_toc.html echo "Pravim $chapter_toc_file\n"; touch ("$chapter_toc_file"); // napravljen $fp_chapter_toc = fopen ("$chapter_toc_file", a); // otvori toc za chapter fputs($fp_chapter_toc, $htmlhead); // stavi header i to. fputs($fp_chapter_toc, "<a href=\"../toc.html\">(natrag)</a><br><b>".$polje[$i]."</b>\n"."<div class=\"chapter_naslov\"><b><i>$chapter_naslov</i></b></div>\n"); // stavi naslov chaptera fclose($fp_chapter_toc); // zatvori TOC (??? zašto) $fp_global_toc = fopen($global_toc_html, a); // otvori globalni TOC fputs ($fp_global_toc, "<li><a href=\"$chapter/$chapter"."_toc.html\" class=\"chapter_link\">$chapter_naslov</a><br>\n"); //stavi link na chapter toc fclose ($fp_global_toc); // zatvori globalni toc $i = $i+2; // spriječi ispis naslova sljedećeg chaptera u zadnji text_ file prethodnog continue; }; if ( ereg( "^Bg [0-9]{1,}\.[0-9]{1,}$", $polje[$i])) { // echo "Našao $polje[$i] u $i redu.\n"; // echo "."; // ovdje bi trebalo resetirati brojače i slično. $text = ereg_replace(" ", "_", $polje[$i+2]); // za text_broj.html touch ("$chapter_dir"."/"."$text".".html"); // pravi Chapter_1/TEXT_1.html if ($fp_text) { fputs ($fp_text, $htmlfoot); fclose ($fp_text); }; $fp_text = fopen("$chapter_dir"."/"."$text".".html", "a"); // Otvara TEXT_1 za stavljanje podataka unutra fputs ($fp_text, $htmlhead); continue; }; if ($fp_text) { if ( ereg("^TEXT.[0-9]{1,}", $polje[$i])) { $fp_chapter_toc = fopen("$chapter_toc_file", "a"); fputs ($fp_chapter_toc, "<a href=\""."$chapter_dir"."/"."$text".".html\" target=\"body\">"."$polje[$i]"."</a><br>\n"); fclose ($fp_chapter_toc); }; if ( ereg("^TEXT.[0-9]{1,}", $polje[$i])) { fputs ($fp_text, "<h2>$chapter_naslov_br : $polje[$i]</h2>\n"); } elseif ( ereg("^TEXT|^SYNO|^PUR|^TRANS", $polje[$i])) { fputs ($fp_text, "<div class=\"naslov\"><b>".$polje[$i]."</b></div>\n"); } else { fputs ($fp_text, $polje[$i]."<br>\n"); }; }; }; fclose ($fp_text); $fp_global_toc = fopen ("$global_toc_html", a); fputs ($fp_global_toc, "</ol>$htmlfoot"); fclose ($fp_global_toc); echo ("Zatvoren toc.html\n"); $end = mtime(); $total = $end - $start; echo "$total\n"; ?> -------------------------------------------------------- -- v Davor Cengija davor@linuxfan.com ==================================== "Please allow 30 days for delivery."

« previous php.version4 (#1250) next »