Re: Is this code thread safe?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I personally still wouldn't cram it into the ViewHelper class.

Make it an independent function, or a static function on a User class
or...

It's jost not directly related to ViewHelper, so don't put it there. :-)

On Wed, June 13, 2007 11:49 pm, Christian Cantrell wrote:
> Thanks, Richard.
> The ViewHelper does do other things for me.  It's sort of a general
> view
> utility class.
>
> I was very close to just basically in-lining the logic as you point
> out,
> however it's possible that I could change the criteria that I use to
> determine if someone is logged in or not, so I figured I'd better put
> the
> code all in one place.  Even if I just change the name of the session
> variable, it'll be nice to just have to change it in one class.
>
> I'm not usually one to go overboard with OOP, but this seemed like a
> good
> use case.
>
> Thanks again for the info.
>
> Christian
>
> On 6/13/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
>>
>> On Wed, June 13, 2007 10:52 am, Christian Cantrell wrote:
>> > I'm pretty sure this code is thread safe, but I just want to be
>> 100%
>> > sure.
>> > I have a class called ViewHelper with a static function called
>> > is_signed_in.
>> >  All it does is check the session for the existence of a
>> particular
>> > variable, and if it's there, it returns true, otherwise false.
>> >
>> > Since the function is static, is there any way this code is not
>> thread
>> > safe?
>> >  Is there any way I could be checking someone else's session if
>> the
>> > requests
>> > are concurrent?
>>
>> Well, I'm not sure how your ViewHelper could possibly screw things
>> up,
>> but the $_SESSION variable is already thread-safe, unless you've
>> hacked up a custom session handler that isn't thread-safe...  In
>> which
>> case you've got bigger problems than just this one function. :-v
>>
>> $_SESSION gets a lock on the session data file at session_start
>> which
>> is not released until session_*close
>>
>> So instead off all that OOP stuff, if you just did:
>> if (isset($_SESSION['is_logged_in'])){
>> }
>> and used unset($_SESSION['is_logged_in']) to log somebody out, well,
>> you'd pretty much have the same functionality in a lot less lines of
>> code...
>>
>> But, hey, I'm sure the ViewHelper has a lot of other Added Value,
>> right?
>>
>>
>> --
>> Some people have a "gift" link here.
>> Know what I want?
>> I want you to buy a CD from some indie artist.
>> http://cdbaby.com/browse/from/lynch
>> Yeah, I get a buck. So?
>>
>>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux