4

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

Community
  • 1
  • 1
doncadavona
  • 7,162
  • 9
  • 41
  • 54

2 Answers2

2

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.

chugadie
  • 2,786
  • 1
  • 24
  • 33
  • You are correct `session()->save()` makes a call to `session_write_close()` which lets you keep long-running pages, such as a thumbnailer, from blocking pages opened in other tabs (or made in parallel via AJAX) – Adam Albright Nov 15 '18 at 01:04
0

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.

Vandolph Reyes
  • 622
  • 6
  • 18