|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-12-10 06:54 UTC] alex at pc4p dot net
[2003-12-10 06:57 UTC] vijolicni dot oblak at gmx dot net
[2003-12-10 07:03 UTC] vijolicni dot oblak at gmx dot net
[2003-12-10 09:16 UTC] sniper@php.net
[2003-12-10 09:17 UTC] sniper@php.net
[2003-12-10 09:52 UTC] vijolicni dot oblak at gmx dot net
[2003-12-10 10:08 UTC] vijolicni dot oblak at gmx dot net
[2003-12-10 10:35 UTC] sniper@php.net
[2010-12-31 21:04 UTC] jani@php.net
-Status: Open
+Status: Closed
-Package: Feature/Change Request
+Package: *General Issues
-Assigned To:
+Assigned To: jani
[2010-12-31 21:04 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 17:00:01 2025 UTC |
Description: ------------ There is obviously some kind of tracing of what happens to variables through their lifetime ? a kind of optimization, I guess. But there is a problem when doing str_replace on large html files (more than 600kb): memory usage jumps from 350MB to 1.8GB according to Windows Task Manager performance monitor. My computer has 512MB physical memory and having more that one gigabyte of quickly changing data in swap file doesn?t help performance at all. It renders my system to almost unresponsive. I solved the problem by doing some ?disoptimizations?: I put the contents of variable $htmlfile, that str_replace was done on to a new variable $tempvar, then I unset($htmlfile), and then reestablish $htmlfile as a new variable with $tempvar as it contents and continue execution where ended [?case? is used as a ?goto? statement]. The set-unset code is commented. The solution to the problem should be that Zend Engine or whatever module is responsible for string tracing and/or memory management should check how much !physical! memory is available and never waste more that hundred(s) of available !physical! MBs on a script, but it should never run into swap file memory gigabytes for ?optimizations?. [I have my swap file on Windows2003 set to 4GB if this is of any relevance] Reproduce code: --------------- $htmlfile=str_replace("\t",' ',$htmlfile); //if (sovertime(8)) savestate($destfilename,$htmlfile,10); return outr(10); case 10: while ($pos=strpos($htmlfile,' ')) { $htmlfile=str_replace(' ',' ',$htmlfile); if ($pos===false) break;} //if (sovertime(8)) savestate($destfilename,$htmlfile,20); return outr(20); case 20: while ($pos=strpos($htmlfile,"\r\n\r\n")) { $htmlfile=str_replace("\r\n\r\n","\r\n",$htmlfile); if ($pos===false) break;} //if (sovertime(8)) savestate($destfilename,$htmlfile,30); return outr(30); case 30: while ($pos=strpos($htmlfile,"\r\n ")) { $htmlfile=str_replace("\r\n ","\r\n",$htmlfile); if ($pos===false) break;} //if (sovertime(8)) savestate($destfilename,$htmlfile,40); return outr(40); case 40: while ($pos=strpos($htmlfile," \r\n")) { $htmlfile=str_replace(" \r\n","\r\n",$htmlfile); if ($pos===false) break;} $htmlfile=str_replace('<table ','<table width=100% ',$htmlfile); $htmlfile=str_replace('<TABLE ','<TABLE width=100% ',$htmlfile); $htmlfile=str_replace('<table>','<table width=100%>',$htmlfile); $htmlfile=str_replace('<TABLE>','<TABLE width=100%>',$htmlfile); //if (sovertime(8)) savestate($destfilename,$htmlfile,105);return outr(105);case 105: $htmlfile=str_replace('Š','?',$htmlfile); $htmlfile=str_replace('š','?',$htmlfile); $htmlfile=str_replace('Č','?',$htmlfile); $htmlfile=str_replace('č','?',$htmlfile); $htmlfile=str_replace('Ž','?',$htmlfile); $htmlfile=str_replace('ž','?',$htmlfile); //if (sovertime(8)) savestate($destfilename,$htmlfile,110);return outr(110);case 110: $htmlfile=str_replace('<table>','<table width=100%>',$htmlfile); $htmlfile=str_replace('<TABLE>','<TABLE width=100%>',$htmlfile); $htmlfile=str_replace('background:','bx:',$htmlfile); $htmlfile=str_replace('mso-highlight:','bx:',$htmlfile); $htmlfile=str_replace('text-align:justify','text-align:left',$htmlfile); Expected result: ---------------- Usage of only of available physical RAM as a tempspace for optimizations. Actual result: -------------- Usage of only of more than 1GB of swapfile as a tempspace for 'optimization' of a script.