ID:               26577
 Updated by:       [EMAIL PROTECTED]
 Reported By:      vijolicni dot oblak at gmx dot net
 Status:           Bogus
 Bug Type:         Strings related
 Operating System: Windows 2003
 PHP Version:      4.3.4
 New Comment:

See also: php.ini, memory_limit directive..



Previous Comments:
------------------------------------------------------------------------

[2003-12-10 09:16:57] [EMAIL PROTECTED]

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Your argument that PHP "should not do this or that" is flawed. 
This works just as expected. There are dozens of other ways too how you
can "shoot yourself in the leg"..


------------------------------------------------------------------------

[2003-12-10 07:03:41] vijolicni dot oblak at gmx dot net

To alex.
Regardless how inefficient the code is, the PHP engine should never be
allowed to almost handicap a rented server that should serve requests
for 30+ sites.

------------------------------------------------------------------------

[2003-12-10 06:57:23] vijolicni dot oblak at gmx dot net

- On the server the script is going to run the script execution just
ended with
FATAL: emalloc() : Unable to allocate 418kB bytes

- On my local computer the swapfile utilisation was so high that the
script wan't able to save a 500kB file to a file and exit in 8 seconds
(the saving function started at 22seconds since the start and ran into
30s limit) [sovertime= start_overtime, and parameter 8 means that it
should save result and end execution at 22seconds, not to reach the 30s
limit]

------------------------------------------------------------------------

[2003-12-10 06:54:35] alex at pc4p dot net

As a personal sidenote, I find your code highly inefficient and thus it
is no wonder, that you reach the limits on your system. You should
definetly read up on PREGs and http://www.php.net/preg_replace which is
much faster than str_replace. str_replace should only be used for small
strings and small replacements, larger tasks are the domain of regular
expressions. Btw. I doubt, that this behaviour is being seen as a
bug...

------------------------------------------------------------------------

[2003-12-10 06:30:40] vijolicni dot oblak at gmx dot net

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('&Scaron;','Š',$htmlfile);
  $htmlfile=str_replace('&scaron;','š',$htmlfile);
  $htmlfile=str_replace('&Ccaron;','È',$htmlfile);
  $htmlfile=str_replace('&ccaron;','è',$htmlfile);
  $htmlfile=str_replace('&Zcaron;','Ž',$htmlfile);
  $htmlfile=str_replace('&zcaron;','ž',$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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26577&edit=1

Reply via email to