php-general Digest 8 Jun 2011 19:48:07 -0000 Issue 7351

Topics (messages 313460 through 313469):

Re: ftell Issue or Feature
        313460 by: Frank Arensmeier
        313463 by: Richard Quadling
        313464 by: Christian Grobmeier
        313465 by: Stuart Dallas
        313466 by: Christian Grobmeier

Re: Going crazy with include & require not working
        313461 by: Richard Quadling
        313462 by: Richard Quadling

Re: advice on how to build this array from an array.
        313467 by: David Robley

Re: php-cli-shebang
        313468 by: Joe Francis

PHP_INI_SCAN_DIR or PHPIniScanDir
        313469 by: Lester Caine

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
On 8 June 2011 10:19, Frank Arensmeier <[email protected]> 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

--- End Message ---
--- Begin Message ---
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 <[email protected]> wrote:
> On 8 June 2011 10:19, Frank Arensmeier <[email protected]> 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

--- End Message ---
--- Begin Message ---
On Wed, Jun 8, 2011 at 8:09 AM, Christian Grobmeier <[email protected]>wrote:

> 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.


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.

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/

--- End Message ---
--- Begin Message ---
> 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

--- End Message ---
--- Begin Message ---
On 7 June 2011 22:17, Brian Dunning <[email protected]> wrote:
> Thanks, this helped me solve it. FPDI extends a class in FPDF, so I simply 
> had to reverse the order in which I call them and all is hunky dory.

I would take a look at using an autoloader
(http://www.php.net/manual/en/language.oop5.autoload.php and
http://uk.php.net/manual/en/ref.spl.php).


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
On 8 June 2011 10:21, Richard Quadling <[email protected]> wrote:
> On 7 June 2011 22:17, Brian Dunning <[email protected]> wrote:
>> Thanks, this helped me solve it. FPDI extends a class in FPDF, so I simply 
>> had to reverse the order in which I call them and all is hunky dory.
>
> I would take a look at using an autoloader
> (http://www.php.net/manual/en/language.oop5.autoload.php and
> http://uk.php.net/manual/en/ref.spl.php).

And having got your own autoloader created, I use auto_prepend_file to
always include it.

http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
Adam Preece wrote:

> hi all,
> 
> please forgive me if i do not make sense, ill try my best to explain.
> 
> 
> i have this array or arrays.
> 
> Array ( [name] => super duplex stainless steels [id] => 30 [page_cat_id]
> => 10 [main_nav] => true [cat_name] => material range ) Array ( [name] =>
> standard stainless steels [id] => 31 [page_cat_id] => 10 [main_nav] =>
> true [cat_name] => material range )
>  Array ( [name] => non ferrous [id] => 32 [page_cat_id] => 10 [main_nav]
>  => true [cat_name] => material range )
> Array ( [name] => carbon based steels [id] => 33 [page_cat_id] => 10
> [main_nav] => true [cat_name] => material range )
> 
> is it possible to build an array  and use the [cat_name] as the key and
> assign all the pages to that cat_name?
> 
> what im trying to achieve is a category of pages but i want the cat_name
> as the key to all the pages associated to it
> 
> hope i make sense
> 
> kind regards
> 
> Adam

How is this array created? If it is from a database, you could probably
modify the query to give you what you want.


Cheers
-- 
David Robley

Show me a sane man. I'll cure him for you.
Today is Prickle-Prickle, the 13rd day of Confusion in the YOLD 3177. 


--- End Message ---
--- Begin Message ---
why not using php.exe instead of php-cgi.exe as a parser ?

On Wed, Jun 8, 2011 at 7:42 AM, Lists <[email protected]> wrote:

> Lists wrote:
>
>> Windows Server 2003
>> PHP fastcgi 5.2
>>
>
>
>
> O.K. '-q' is quiet mode (no header info), which works better when not using
> the -f flag when calling the script (it appears).
>
> anyway, I solved my issues with a work around, so no worries.
>
>
> Donovan
>
>
> --
> dbrooke
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Powered By Francis™.
Welcome to my website: http://www.francistm.com
Rewrite to [email protected] please.

--- End Message ---
--- Begin Message --- OK, I'm trying to set up my windows setup to work with separate .ini files for each of the extra extensions as the Linux distributions do. I've got a \conf\ directory with the php.ini in and then \conf\conf.d\ with a few windows versions of the SUSE linux files. I can see references to PHP_INI_SCAN_DIR and PHPIniScanDir but I can't find any definitive manual page on what or how ... or am I barking up the wrong tree?

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---

Reply via email to