I made a long script in PHP as such:
ignore_user_abort(true);
set_time_limit(0);
It runs perfectly in the background even if I close the page. My problem is that I can't open other PHP files until this script finishes running in the background. How can I solve this problem?
When a PHP script uses sessions, PHP locks the session file until the script completes. A page request that tries to use a locked session is blocked until the session file is released. PHP does this so that sessions remains in a consistent state. Quote from PHP bug #31464:
The simplest workaround as described above and here as well is:
session_start()
session_write_close()
As mentioned in comments, Sessions are the problem - this is because the session file is locked.
Use
session_write_close()
in your long-running script to unlock the session file, but note that you cannot use$_SESSION
variables in that particular script afterwards.