php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56088 out of memory with log4php
Submitted: 2004-06-08 18:02 UTC Modified: 2006-02-24 02:05 UTC
From: swen at grmblfrz dot de Assigned: rasmus (profile)
Status: Closed Package: APC (PECL)
PHP Version: 4.3.11, 4.4.0 OS: Solaris 2.8, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: swen at grmblfrz dot de
New email:
PHP Version: OS:

 

 [2004-06-08 18:02 UTC] swen at grmblfrz dot de
Description:
------------
apc seems to have a problem with log4php: when trying to load
LoggerAppenderFile.php it will fill all the available shared memory, because it caches the same class again and again (or so it seems).

The following patch seems to fix this, but I really have no idea, why. Again
I did some guessing by looking at the source of turck-mmcache. But
this might be a starting point.

Again, please give me feedback...

diff -u -b -r3.7 apc_compile.c
--- apc_compile.c       1 Jun 2004 21:16:54 -0000       3.7
+++ apc_compile.c       8 Jun 2004 22:09:33 -0000
@@ -219,6 +219,7 @@
         break;
 
     case IS_OBJECT:
+#if 0
         CHECK(dst->value.obj.ce =
             my_copy_class_entry(NULL, src->value.obj.ce, allocate));
 
@@ -228,6 +229,7 @@
                               (ht_copy_fun_t) my_copy_zval_ptr,
                               1,
                               allocate));
+#endif
         break;
 
     default:


Reproduce code:
---------------
<?php
define('LOG4PHP_CONFIGURATION', 'WEB-INF/log4php.xml');
include_once('log4php/LoggerManager.php');

$log = &LoggerManager::getLogger($name);

$log->info("test, ey");

?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-07 00:43 UTC] rasmus@php.net
This was fixed a while ago
 [2004-09-10 12:27 UTC] swen dot thuemmler at telefonica dot de
Unfortunately, the latest version from CVS does not fix
this bug for me. (Solaris 2.8, php 4.3.7, Apache 2.0.49)

--Swen
 [2004-09-16 05:02 UTC] swen dot thuemmler at telefonica dot de
Some more data points: without my patch, the web server hangs as soon as I start using log4php. I was able to call apcinfo.php in between (code:
<?php   
print_r(apc_cache_info());
print_r(apc_sma_info());
?>)
There already was much less available memory than usual, and there were already about 13000 entries in the block lists:
Array
(
    [num_seg] => 1
    [seg_size] => 94371840
    [avail_mem] => 56568904
    [block_lists] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [size] => 664
                            [offset] => 16359304
                        )

                    [1] => Array
                        (
                            [size] => 664
                            [offset] => 16395304
                        )

                    [2] => Array
                        (
                            [size] => 1096
                            [offset] => 16430872
                        )

[...]

                    [12867] => Array
                        (
                            [size] => 640
                            [offset] => 94340816
                        )

                    [12868] => Array
                        (
                            [size] => 144
                            [offset] => 94341496
                        )

                    [12869] => Array
                        (
                            [size] => 12288
                            [offset] => 94341680
                        )

                    [12870] => Array
                        (
                            [size] => 640
                            [offset] => 94358816
                        )

                    [12871] => Array
                        (
                            [size] => 144
                            [offset] => 94359496
                        )

                    [12872] => Array
                        (
                            [size] => 704
                            [offset] => 94371128
                        )

                )

        )

)

There is a pattern here: the blocks with sizes 144, 12288 and 640 are repeated over and over again.

Perhaps this helps you hunting the bug.

Greetings, Swen
 [2005-09-13 05:05 UTC] swen dot thuemmler at telefonica dot de
I have the same problem with the lates version from CVS. I need the following patch to get decent performance, without it it feels like without APC, and apc_sma_info() shows there are numerous blocks of memory fragments:

diff -u -r3.26 apc_compile.c
--- apc_compile.c       24 Aug 2005 15:50:45 -0000      3.26
+++ apc_compile.c       13 Sep 2005 09:00:28 -0000
@@ -393,6 +393,7 @@
 
     case IS_OBJECT:
 #ifndef ZEND_ENGINE_2        
+#if 0
         CHECK(dst->value.obj.ce =
             my_copy_class_entry(NULL, src->value.obj.ce, allocate, deallocate));
 
@@ -405,6 +406,7 @@
             my_destroy_class_entry(dst->value.obj.ce, deallocate);
             return NULL;
         }
+#endif
         break;
 #else
        dst->type = IS_NULL;


Hope this helps

--Swen
 [2005-09-13 09:42 UTC] swen dot thuemmler at web dot de
Here is a recipe to reproduce the effect:
1. download log4php-0.9 (http://logging.apache.org/log4php/download.html)
2. unpack it (this creates a subdirectory log4php-0.9
3. create the file log4php.xml (important!)
<?xml version="1.0" encoding="ISO-8859-1"?>
<log4php:configuration xmlns:log4php="http://www.vxr.it/log4php/" threshold="all" debug="false">
    <appender name="default" class="LoggerAppenderEcho">
        <layout class="LoggerLayoutTTCC">
            <param name="threadPrinting" value="true" />
            <param name="categoryPrefixing" value="true" />
            <param name="contextPrinting" value="true" />
            <param name="microSecondsPrinting" value="true" />
            <param name="dateFormat" value="[%c]" />
        </layout>
    </appender>

    <appender name="rolling" class="LoggerAppenderRollingFile">
        <param name="file" value="test.log" />
        <param name="MaxFileSize" value="256KB" />
        <param name="MaxBackupIndex" value="3" />
        <layout class="LoggerLayoutTTCC" />
    </appender>
    
    <root>
        <level value="info" />
        <appender_ref ref="rolling" />
    </root>
</log4php:configuration>

4. create the file apctest.php:
<?php
define('LIB_LOG4PHP', 'log4php-0.9/src/log4php/');
define('LOG4PHP_CONFIGURATION', 'log4php.xml');
include_once(LIB_LOG4PHP.'LoggerManager.php');
$log = &LoggerManager::getLogger('dummy');
$log->info('test');
?>
<html><head></head><body><p>Hello</p></body></html>

5. create the file apcinfo.php:
<html><head></head><body><pre>
<?php   
print_r(apc_cache_info());
print_r(apc_sma_info());
?>
</pre></body></html>

6. restart your webserver
7. call apctest.php from your web-browser
8. call apcinfo.php from your web-browser

Notice the many fragments in the output of apc_sma_info().
The weired thing is, if you remove the superfluous first appender from the log4php.xml, the effect is not shown.

With my patch, everything is back to normal.


Greetings, Swen
 [2005-10-23 09:48 UTC] mike@php.net
Please try the latest package version and report back if you're still experiencing this issue.
 [2005-10-24 04:51 UTC] swen dot thuemmler at web dot de
Still the same symptoms with the latest version from CVS.

--Swen
 [2005-12-09 05:23 UTC] swen at grmblfrz dot de
see bug #5111, seems to have the same symptoms
 [2006-02-24 02:05 UTC] rasmus@php.net
This should be fixed in CVS now.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:25 2019 UTC