How to session_write_close() in Laravel?

2.1k Views Asked by At

Running session_write_close() before sleep() in Laravel doesn't seem to be functioning as the session is still blocked from other requests until the current connection is complete.

I'm trying to sleep() in Laravel without blocking other requests. Found out that session_write_close() should resolve the problem as mentioned here: Long polling in Laravel (sleep() function make application freeze). But it doesn't work. sleep() is still blocking other requests.

The project app is a chat app using regular polling and long-polling: http://github.com/doncadavona/laravel-angularjs-chat

Directly to the code: https://github.com/doncadavona/laravel-angularjs-chat/blob/master/app/Http/Controllers/MessagesController.php

2

There are 2 best solutions below

1
On

Laravel doesn't use PHP's session handling functions. You must use

$request->session()->save();

to call a handler's write method. But, since Laravel also doesn't implement any session locking mechanism, you are unlikely to see any session related blocking, nor should you see any change in ajax behavior because you saved/closed the session.

2
On

You can't use session_start() or session_write_close() in laravel.

Laravel doesn't seem to be functioning as the session is still blocked from other requests until the current connection is complete.

This is already a nature of PHP, thats why AJAX was created in order for us to have multiple request at the same time.