Multiple php requests simultaneously, second request doesn't finishe until first finishes

Viewed 118

When I am using XAMP Server with PHP 5.6

  • sleep(10) // sleep for 10 seconds and call other localhost php file, it will work smoothly.

When I am using XAMP Server with PHP 7.4.9

  • sleep(10) // sleep for 10 seconds and call other localhost file, it will hang until first finishes

-- Anything I need to change XAMP configuration for request will not wait until first finish

1 Answers

File1.php

<?php

session_start();
sleep(1);
echo "I am File2";

?>

File2.php

<?php

session_start();
sleep(10);
echo "I am File2";

?>

When you run above File2.php first and after run File1.php still need to finish the running process of File2.php

When you session_start(); after you are not writing session then you have to close the session using session_write_close();

File1.php

<?php

session_start();
session_write_close();
sleep(1);
echo "I am File2";

?>

File2.php

<?php

session_start();
session_write_close();
sleep(10);
echo "I am File2";

?>

Now you can run File2.php and after File1.php then you will execute File1.php first

Related