Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Sessions blocks other requests
  • On my page, I use 2 async ajax calls and sessions (with default config).

    The problem is, that one of the calls is quite slow (>1s), but only if you run both requests at the same time. I think its because of session (b)locking.

    Because i dont write to the session, just reading in this requests, I tried now to to the following in the app bootstrap:


    if(in_array($_SERVER["REDIRECT_URL"], array(
    "/ajax/request1",
    "/ajax/request2"
    ))) {
    session_write_close();
    }

    But this doesn't solve the problem. Any ideas how to fix this issue?
  • Here you can see the 2 ajax requests.

    In first screenshot, you see the concurrent requests:


    The second screenshot is, when only requesting one:


    As you can see, the "slow" request for "available", isn't slow, if you only call a single request
  • Fuel's own session drivers are non blocking (but may have concurrency issues when updating the session), PHP's own session handling is blocking (for exactly that reason).

    session_write_close() is a PHP statement, which Fuel doesn't use. 

    You mention you use "the default settings". The default is using a cookie, it has no backend storage at all that could cause any locking. All other drivers are non-blocking, apart from their I/O itself (i.e. the file driver locks the file, read or writes, unlocks the file, the database takes care of atomic operations itself, etc).

    When you use concurrent "async" requests, writing to the session is a bad idea because of this, as you don't know which requests will be overwriting what.

    Perhaps you can enable the profiler, and set "log_profile_data" to true in your config (you need to be up to date for this), to have the profile data of the requests logged, so you may see where the delay is?
  • With default settings, I mean I have not created my own session.php config file, so yes, cookies are used.

    I have tried to activate this log_profile_data flag and now its logging (creating log files like 06-profiler-20170206142058.php), but only the "main"-request (not ajax request) is logged correctly. For the 2 ajax requests, there is only ONE log file created, but its empty (only with "" in it)??

    Maybe its because they are generated by a \Controller_Rest controller?

    And as I said, the requests itself are not slow (if I call them directly, not async with the other ajax request). I tried both of them separate.
  • Ok, I now compared my local dev maschine (Windows, XAMP, php 5.6.12), and there is no issue. Both requests are done within 280 ms.

    The problem only occurs on my remote Linux server with PHP Version 5.5.9-1ubuntu4.20.

    I have switched the PHP version to 5.6.29 and now its working as expected. So maybe its an php bug in this version.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion