1

I've used the session_start() func in the ajax files.
First File:

<?php
// First File
if(session_id() == '')
    session_start();
sleep(10);

And Second File: (run after 10 seconds, I don't know Why!)

<?php
// Second File
if(session_id() == '')
    session_start();
echo 'Second File'; // print after 10 seconds...

When I'm run two Ajax files at the same time, the second file will wait(pending) until the first file to be completed.
What is the reason? The problem has resolved when i removed session_start().
How to solve this problem?

Solution: session_write_close(); and PHP Session Lockes

<?php
        // First File
        if(session_id() == '')
            session_start();
        session_write_close();
        sleep(10);
Community
  • 1
  • 1
Mohsen Movahed
  • 418
  • 5
  • 22

2 Answers2

1

Solution: session_write_close(); and PHP Session Lockes

<?php
        // First File
        if(session_id() == '')
            session_start();
        session_write_close();
        sleep(10);
Mohsen Movahed
  • 418
  • 5
  • 22
0

sleep(10) means wait for 10 seconds.It is used for adding delay in code. check here

Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52
Dinesh Belkare
  • 639
  • 8
  • 24