[PHP] ftell Issue or Feature

2011-06-08 Thread Christian Grobmeier
Hello,

I am one of the log4php [1] hackers over at the ASF. We (thats Ivan
Habunek and myself) have now a nasty issue for which we would be glad
about input.

Use case:
Once the log file got a specific size, it will be rolled over. In
other terms, the big logfile gets closed and a new one is opened. This
is supposed to work in a multithreaded environment of course. The user
now claims about multiple creations of small logfiles.

Code [2]:

if(ftell($this->fp) > $this->getMaxFileSize()) {
if(flock($this->fp, LOCK_EX)) {
if(ftell($this->fp) > $this->getMaxFileSize()) {
$this->rollOver();
}
}
}

This is the rollover code. We check with ftell, were the latest
position is and if it is to big, we try to get a lock. If it is to big
after we have the lock, we roll it over.

Here mulitiple threads can reach the flock position- then they all
wait until they get the lock of this file. If it has been rolled by a
previous thread, they should have got an updated reference to
$this->fp and skip the rolling.

So, Ivan found out that in the case, we do the second ftell we do not
get updated positions when another thread has written into the file.
The object itself is always the same, for all threads. Every thread
gets this "Appender" from a kind of a pool.

My guess is, every thread gets some kind of a copy of this object,
working at it. Once it reaches the method, its members states are not
reflected into the other stack call.

Docs don't tell me anything for my case. I would be really glad about
suggestions, help, links whatever.

Thanks!

Cheers,
Christian

[1] logging.apache.org/log4php
[2] 
https://svn.apache.org/repos/asf/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ftell Issue or Feature

2011-06-08 Thread Christian Grobmeier
Thanks guys.

I will test it together with Ivan and hopefully the user.

Never heard of this function before, very cool that you have
identified the problem so quickly.

Thanks again!

On Wed, Jun 8, 2011 at 11:41 AM, Richard Quadling  wrote:
> On 8 June 2011 10:19, Frank Arensmeier  wrote:
>> 8 jun 2011 kl. 09.09 skrev Christian Grobmeier:
>>
>>> The object itself is always the same, for all threads. Every thread
>>> gets this "Appender" from a kind of a pool.
>>>
>>> My guess is, every thread gets some kind of a copy of this object,
>>> working at it. Once it reaches the method, its members states are not
>>> reflected into the other stack call.
>>
>> I never worked with "log4php", so I am really not sure how "getMaxFileSize" 
>> calculates the log file size. In general, results for functions like PHP's 
>> "filesize" are cached. See e.g. 
>> http://php.net/manual/en/function.filesize.php
>>
>> Right after the flock call, try to clear the cache with clearstatcache().
>>
>> Maybe that helps.
>> /frank
>
>
> if((ftell($this->fp) > ($maxFileSize = $this->getMaxFileSize())) &&
> flock($this->fp, LOCK_EX)) {
>        clearstatcache();
>        if(ftell($this->fp) > $maxFileSize) {
>               $this->rollOver();
>       }
> }
>
> would be my take.
>
>
> --
> Richard Quadling
> Twitter : EE : Zend : PHPDoc
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
>



-- 
http://www.grobmeier.de

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ftell Issue or Feature

2011-06-08 Thread Christian Grobmeier
> Assuming each thread has its own copy of $this->fp, even after renaming the
> log file all other threads will still be pointing at the old file. The
> resource is connected to the inode, not the filename, so even if the
> filename changes the inode does not, therefore the actual location on disk
> represented by the resource does not.

Actually I thought pretty similar before. I will test the option below too

thanks!

> I would fix this by doing the following after acquiring the lock...
> 1. Close the file
> 2. Reopen the file
> 3. Seek to the end
> 4. Then do the ftell
> Alternatively it could just do a filesize on the filename to get the current
> size rather than using ftell on the resource. If the size is less than ftell
> then another thread has rolled it over and this thread needs to close and
> reopen the file. If they match, roll the file over.
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/



-- 
http://www.grobmeier.de

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Bug 51860

2012-01-17 Thread Christian Grobmeier
Hello folks,

any chance this one is ever fixed?
https://bugs.php.net/bug.php?id=51860

I am a customer of 1&1. They told me they will not upgrade until this
one is fixed. Imagine that there are thousands of customers running
php 5.2.17 just because of this issue. Unfortunately I am not able to
fix this on myself - my C-fu is not good enough.

Because big hosters like 1&1 do not upgrade, we (the Apache log4php
team) cannot make use of newer PHP versions too. We have decided to
use the features once we see the old hosters move on. Same is true for
other projects of mine. If we would upgrade we loose all the people on
the big hosting companies.

I think it is in the interest of the PHP-dev team to see people moving
on. Otherwise at someday software like phpBB, wordpress et al will not
work on many hosts at some day in future.

Not sure if there has been any plans on this issue - i am very much
interested in this and would like know if it is already on the
schedule.

Thanks,
Christian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php