This has been a difficult problem to search for, as all search results describe AJAX requests from javascript. Technically AJAX from javascript COULD solve my issue, but I'd prefer this to be solved purely server side using PHP.
Here's a breakdown of what's going on so far. I've simplified the code a lot.
CustomerOrderForm.php:
<form action="CreateOrder.php" method="post" onsubmit="this.submitButton.disabled = true;">
<input name="first">
<input name="second">
<button type="submit">Place Order</button>
</form>
CreateOrder.php
<?php
basicOrderProcesses($_POST['first'],$_POST['second']);
header("Location: PaymentMethod.php?first=$_POST['first']&second=$_POST['second']");
slowOrderProcesses($_POST['first'],$_POST['second']);
die();
function basicOrderProcesses(){
//Code that is absolutely essential to processing payment
}
function slowOrderProcesses(){
//Very time consuming code that I'd rather the customer doesn't have to wait for
}
PaymentMethod.php
<h1>Please Select Your Payment Method</h1>
...
//You get the idea
I thought it was working fine, but as slowOrderProcesses() got bigger, the code ran slower. I see now that it never was running in the background, and the page isn't redirecting until slowOrderProcesses() is completed.
If CreateOrder.php were running in javascript, I could easily write an AJAX solution like this one. But it's running in pure php. What's the equivalent php solution? Remember, I need the slow processes to run while the customer is choosing a payment method. (And maybe even continue to run after the customer has paid, if the customer is fast enough.)
I'm hoping the solution won't require too much rewriting, but I gotta do what I gotta do. (I try to avoid installing libraries if I can help it.)