Code loading and run order in PHP 8.1

Hi All

The system I have written has changed the way it works since I have upgraded from PHP 7.something to 8.1.

Some code can take some time to run so I have added a loading/waiting icon and text.

Before PHP 8.1 when someone went to the next step the loading icon would show and the code would run behind it and then the user would be redirected to a success or fail message.

After PHP 8.1 when someone goes to the next step it appears that all the code is run before moving to the next step so that the loading icon does not show and it looks like the website is very slow or not working.

Any idea how I can fix this so that the loading icon will display while the code behind it is running?


Well keep in mind that PHP 8 brought JIT compiling which significantly increases the speed of some PHP processing. Not a huge jump, but it can be noticeable.

Now, having said that, without providing your code you are asking us to comment on all theoretical code. Maybe show us what your script does and what you have tried to test it. Right now all you have is “I have this thing that isn’t working before, but it worked before, and now doesn’t work. Can you help me?”



Thanks for your reply.

This is generic as I use the loading code all over the place.

For example… a user completes a form and submits it…

Previously the form would go to the part of my code that processes the submitted form and displays the loading code:

<div class="text-center"><h1 class="myHeaderColour">PROCESSING</h1></div>

<div class="text-center"><img src="signup/images/loading.gif" class="img-fluid"><br><strong>one moment please...</strong><br><br>this could take up to a minute...<br>do not refresh or leave this page...</div>

Then under the loading code is my PHP, which is working fine, and then while the loading code showed the PHP tasks would run under it.

I use this when I need to, generally, process requests using third-party API’s such as processing a credit card, or cPanel API commands like creating an account, email management, domain management, when registering a domain with the registry etc.

Now it appears that when someone submits the form they stay on the form page while the code under the loading code runs then once completed shows the loading code for a split second and then moves on.

I suspect that something in PHP 8.1 has changed the way this processes but am not sure how to fix it.

Any ideas?


Is this something to do with output buffering, perhaps a different default in your new php.ini file?

Is the html you showed part of the form processing code, or part of the form submission code? If it’s part of the form processing code, then I’m more surprised it was showing up while the rest of the PHP code is doing its work. I must say, though, that I don’t have a lot of experience of running stuff that takes many seconds to execute. As I recall it, if I submit a form that will take a lot of processing (import a few thousand CSV lines, for example) I don’t see any output from the processing code until it’s all done. It’s been a while, though.

As droop mentions, there’s no way this code in PHP shows, regardless of version. If you’re using Javascript to submit your form through an AJAX process, then your question is related to 1) Javascript handling and 2) PHP execution speed. If it’s output buffering, you’d still have PHP code about output buffering around this loading code, as even with any php.ini changes, PHP still needs to know which parts of the buffer to flush to the client and which parts to hold.


I have spent a lot of time on this as it was working the way I wanted and now it isn’t.

It is just a basic form submit… nothing special… and as mentioned I use it all over the place and it has changed the way it works everywhere so it is not just one set of code.

I went down the path of buffering and everything there seems fine.

I have updated a pile of third-party code I use such as the PHPMailer code, credit card processing code, pdf-creator code etc however none of them are specific to the issue from what I can work out.

I have created a work around that seems to be doing the job… I am submitting the form to a loading page that the creates a form with hidden values and submits it to the processing code… the processing code runs while stuck on the loading page.

It is a pain but it seems to be working.

Thanks for all the help.


1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.