Welcome! Log In Create A New Profile

Advanced

[PHP] Get out of corrupted session

Posted by Côme Chilliet 
Côme Chilliet
[PHP] Get out of corrupted session
April 26, 2017 04:20PM
Hello,

When there is corrupted or invalid data in the session, it triggers a Fatal error when calling session_start.

My problem is the data is still in the session so there is no way to get out of this fatal error other than deleting the cookie by hand.
I would like to destroy the session in case of fatal error, which seems a pretty reasonnable behavior.

Is there any way to do this ? I heard of register_shutdown_function but it seems to be called even when no errors occurs. Can the method called detect if it was called by a fatal error or not ?

I’d like a solution which works with PHP5 as well (I know that more errors are catchable in PHP7).

Côme

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph M. Becker
[PHP] Re: Get out of corrupted session
April 26, 2017 09:00PM
On 26.04.2017 at 16:13, Côme Chilliet wrote:

> When there is corrupted or invalid data in the session, it triggers a Fatal error when calling session_start.
>
> My problem is the data is still in the session so there is no way to get out of this fatal error other than deleting the cookie by hand.
> I would like to destroy the session in case of fatal error, which seems a pretty reasonnable behavior.
>
> Is there any way to do this ? I heard of register_shutdown_function but it seems to be called even when no errors occurs. Can the method called detect if it was called by a fatal error or not ?

Are you looking for set_error_handler
(http://php.net/manual/en/function.set-error-handler.php)?

--
Christoph M. Becker


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
AshleySheridan
Re: [PHP] Get out of corrupted session
April 27, 2017 01:00AM
On Wed, 2017-04-26 at 16:13 +0200, Côme Chilliet wrote:
> Hello,
>
> When there is corrupted or invalid data in the session, it triggers a
> Fatal error when calling session_start.
>
> My problem is the data is still in the session so there is no way to
> get out of this fatal error other than deleting the cookie by hand.
> I would like to destroy the session in case of fatal error, which
> seems a pretty reasonnable behavior.
>
> Is there any way to do this ? I heard of register_shutdown_function
> but it seems to be called even when no errors occurs. Can the method
> called detect if it was called by a fatal error or not ?
>
> I’d like a solution which works with PHP5 as well (I know that more
> errors are catchable in PHP7).
>
> Côme
>

Have you investigated why the sessions are becoming so corrupted? The
way you ask this question suggests it happens frequently enough to
become a problem.

How are you storing sessions? Are they using standard files on disk, in
RAM, inside a database? Are your sessions long or short lived? How much
data are you most commonly putting into each session object? Are
sessions being somehow load balanced? Are you frequently hitting
sessions, creating possible read/write conflict race conditions?

I think looking to just clear sessions that could be corrupt might be
only treating the symptom, and not dealing with the actual cause of the
problem. This could be only a manifestation of a much larger problem.

--
Thanks,
Ash

http://www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login