4

I have loaded some data using ajax into a div that show the user invoices list. I have to start session to get the user id. It works fine in local host PHP 7.2 but on the server PHP 7.0 It some times says "Unable to clear session lock record" and sometime it works. Can anyone please help me with this issue I will be very thankful...

I have tried to remove the session_start() but it stops my all code. When i change the server PHP 7.0 to 5.0 It works perfect but some of my other libraries stops working due to old version of PHP...

Below is the data that is fetched with ajax in the div. And div shows that warning.

<?php

session_start();

$assoc_id = $_SESSION['ayp_associate_id'];

include('../../../data/db.php');

if (isset($_POST['fetch_data'])) {

    $query = $conn->query("SELECT * FROM `transaction_details` WHERE `agentid` = '$assoc_id' ORDER BY `id` DESC LIMIT 300");

    if ($query->num_rows > 0) {
        while ($row = mysqli_fetch_assoc($query)) {

            $get_book = $conn->query("SELECT `packid` FROM `booking` WHERE `id` = " . $row['bookingid']);

            while ($book = mysqli_fetch_assoc($get_book)) {
                $pack_id = $book['packid'];
            }

            $get_pack = $conn->query("SELECT `package-name` FROM `packages` WHERE `id` = $pack_id");

            if ($get_pack == true) {
                while ($pack = mysqli_fetch_assoc($get_pack)) {
                    $package_name = $pack['package-name'];
                }
            } else {
                $package_name = "Unknown Package!";
            }

            echo "
            <div class='plate shadow bg_light-gray book_plate'>

                <div class='col_2-4'>
                    <h4>bk#" . $row['bookingid'] . " <span class='font_small'>$package_name</span></h4>
                    <p class='no_margin'>£ " . $row['total_amount'] . "</p>
                </div>

                <div class='col_2-4'>
                    <input onclick='show_invoice(" . $row['id'] . ");disable_bubbling(event);' type='button' class='btn btn_w-150 plate_btn float_right m-30-5 bg_default border_none border_radius-5 shadow show_details' value='Show Details'>
                </div>

            </div>
            ";
        }
    } else {
        echo "<div class='error_container'><center><h1>Nothing Found!</h1><p>We Didn't Found Any Invoice Data!</p></center></div>";
    }
}

?>

It should just get the user id from session and load the invoice from the database...

AbcAeffchen
  • 14,400
  • 15
  • 47
  • 66

1 Answers1

4

Setting the following ini settings (also from PHP directly) helped me mitigate this issue on a high load project (~300 concurrent users)

    ini_set('memcached.sess_lock_retries', 10);
    ini_set('memcached.sess_lock_wait_min', 1000);
    ini_set('memcached.sess_lock_wait_max', 2000);
clops
  • 5,085
  • 6
  • 39
  • 53
  • I tried this and it definitely made it less worse.. But i'm still seeing the error pop up about once a day. Do you think it could also help to disable `lazy_write`? I saw someone mention a solution with that as well. – Ludo - Off the record Dec 30 '21 at 18:25