[PHP-BUG] Bug #60982 [NEW]: GC not called prior to memory exhausted error

2012-02-05 Thread developerguy2008 at yahoo dot com
From: 
Operating system: Linux
PHP version:  5.4.0RC7
Package:  Scripting Engine problem
Bug Type: Bug
Bug description:GC not called prior to memory exhausted error

Description:

This affects all versions of PHP. In a script that is about to run out of
memory, gc_collect_cycles() should be called as this can sometimes prevent
the script from running out of memory.

Example:

I have a non-blocking server I wrote in PHP. If there are several thousand
connections, the script will run out of memory. However, if the exact same
script with the exact same load (using apache benchmark) is run while
calling gc_collect_cycles() every half second, there are no out-of-memory
issues.

Test script:
---
The source code for PHP will reveal that garbage collection is not run as a
last ditch effort to continue execution within the memory constraints
specified by the user.

Expected result:

I expect PHP to run garbage collection when memory is nearly exhausted to
prevent a memory error.

Actual result:
--
PHP will exhaust memory even when it is not necessary for it to exhaust
memory.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=60982&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=60982&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=60982&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=60982&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=60982&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60982&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=60982&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=60982&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=60982&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=60982&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=60982&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=60982&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=60982&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=60982&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=60982&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=60982&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=60982&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=60982&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=60982&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=60982&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=60982&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=60982&r=mysqlcfg



[PHP-BUG] Bug #60983 [NEW]: Memory is not properly freed

2012-02-05 Thread developerguy2008 at yahoo dot com
From: 
Operating system: all
PHP version:  5.4.0RC7
Package:  Scripting Engine problem
Bug Type: Bug
Bug description:Memory is not properly freed

Description:

Memory is not being freed properly. In a short loop several megabytes are
lost that should not be lost. Attached is a test script to demonstrate what
I mean.

Test script:
---
$mem1 = memory_get_usage(true);
echo "MEM1: " . $mem1 . "\n";
class A {
public $class;
}

$c1 = $c2 = null;
for ($i = 0; $i < 2; $i++) {
$c1 = new A();
$c2 = new A();
$c1->class = array($c1, $c2);
$c2->class = array($c1, $c2);
}
unset($c1); unset($c2);

gc_collect_cycles();
$mem2 = memory_get_usage(true);
echo "MEM2: " . $mem2 . "\n";
echo "DIFF: " . ($mem2 - $mem1) . "\n";

Expected result:

I expect the memory difference to be 0. In this case it is several
megabytes.

Actual result:
--
MEM1: 4980736
MEM2: 7340032
DIFF: 2359296

The DIFF should be 0.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=60983&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=60983&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=60983&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=60983&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=60983&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60983&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=60983&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=60983&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=60983&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=60983&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=60983&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=60983&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=60983&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=60983&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=60983&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=60983&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=60983&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=60983&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=60983&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=60983&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=60983&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=60983&r=mysqlcfg



Req #60024 [Com]: Do not keep last element treated by foreach referenced

2012-02-05 Thread DeveloperGuy2008 at yahoo dot com
Edit report at https://bugs.php.net/bug.php?id=60024&edit=1

 ID: 60024
 Comment by: DeveloperGuy2008 at yahoo dot com
 Reported by:chealer at gmail dot com
 Summary:Do not keep last element treated by foreach
 referenced
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 PHP Version:5.3.8
 Block user comment: N
 Private report: N

 New Comment:

Please fix this. It creates a lot of hard to debug bugs.


Previous Comments:

[2011-10-09 21:09:19] chealer at gmail dot com

Description:

As explained on http://ca.php.net/manual/en/control-structures.foreach.php :

Warning

Reference of a $value and the last array element remain even after the foreach 
loop. It is recommended to destroy it by unset().


In my opinion, PHP shouldn't keep the last element referenced by default, but 
at least, please provide a syntax which will not keep it. The current 
situations causes bugs like https://bugs.php.net/bug.php?id=49386







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


Bug #60983 [Com]: Memory is not properly freed

2012-02-06 Thread DeveloperGuy2008 at yahoo dot com
Edit report at https://bugs.php.net/bug.php?id=60983&edit=1

 ID: 60983
 Comment by: DeveloperGuy2008 at yahoo dot com
 Reported by:developerguy2008 at yahoo dot com
 Summary:Memory is not properly freed
 Status: Not a bug
 Type:   Bug
 Package:Scripting Engine problem
 Operating System:   all
 PHP Version:5.4.0RC7
 Block user comment: N
 Private report: N

 New Comment:

Do you know any references where I may read about the object_store? Is there a 
to shrink it (like a compile time flag) when it is does not need to be large?

It seems like the ideal result would be to shrink the object store. In this 
example it is only a few megabytes but in other cases it could be several 
hundred megabytes that essentially lost forever (at least to other processes).


Previous Comments:

[2012-02-06 07:46:59] larue...@php.net

the reason for there is mem diff is that, the EG(objects_store) could only be 
grow  but could not be shrunk. 

if you tweak your test into:
$mem1 = memory_get_usage(true);
echo "MEM1: " . $mem1 . "\n";
class A {
public $class;
}

$c1 = $c2 = null;
for ($i = 0; $i < 2; $i++) {
$c1 = new A();
$c2 = new A();
$c1->class = array($c1, $c2);
$c2->class = array($c1, $c2);
   
gc_collect_cycles();

}
unset($c1); unset($c2);

$mem2 = memory_get_usage(true);
echo "MEM2: " . $mem2 . "\n";
echo "DIFF: " . ($mem2 - $mem1) . "\n";

you may understand my point

----------------
[2012-02-06 00:43:46] developerguy2008 at yahoo dot com

Description:

Memory is not being freed properly. In a short loop several megabytes are lost 
that should not be lost. Attached is a test script to demonstrate what I mean.

Test script:
---
$mem1 = memory_get_usage(true);
echo "MEM1: " . $mem1 . "\n";
class A {
public $class;
}

$c1 = $c2 = null;
for ($i = 0; $i < 2; $i++) {
$c1 = new A();
$c2 = new A();
$c1->class = array($c1, $c2);
$c2->class = array($c1, $c2);
}
unset($c1); unset($c2);

gc_collect_cycles();
$mem2 = memory_get_usage(true);
echo "MEM2: " . $mem2 . "\n";
echo "DIFF: " . ($mem2 - $mem1) . "\n";

Expected result:

I expect the memory difference to be 0. In this case it is several megabytes.

Actual result:
--
MEM1: 4980736
MEM2: 7340032
DIFF: 2359296

The DIFF should be 0.






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