0
votes

It's quite possible the answer to this question is "no", but hey. I have a Gravity Forms form inside a Wordpress site - after the user has submitted a form, I have a function I'd like to run to go and collect some extra data for it.

I don't actually think the Gravity Forms/Wordpress parts are very relevant to my question, but I know everyone on stackoverflow likes to see some code. :) Inside functions.php I hook my form's "after submission" event using:

add_action("gform_after_submission_15", "gravityforms_collectreportdata", 10, 2);

This function then does the following:

function gravityforms_collectreportdata($entry, $form) {
ScanForMissingData($entry["post_id"]);
}

The problem is that ScanForMissingData takes some time, and the user is left waiting for it to finish before they get the "form submitted" message. Really I don't need the user to wait for this. I'd like to just start it running on the server and let the user get on with stuff. I'd ideally like to do something like:

function gravityforms_collectreportdata($entry, $form) {
StartInBackground(ScanForMissingData, $entry["post_id"]);
}

Or some such. Is this possible in PHP?

1
i dont think i get it.. but i dont think php have threading support. if you want to continously grab client data, you could set some intervals via javascriptCarlos

1 Answers

0
votes

Hmm, not no, no ;-) Actually there are a couple of ways I can think of.

First, and best, would be if you have shell access to the host or could at least have someone install a cron entry for you. Then you'd defer the function to the cronjob and just record the form data to some kind of queue.

Not possible? Ok, Transmit the form submission response to the user before you start collecting data. Echo the response page (or ajax response whatever it is), perform a flush() (yes, add approx. 1024 bytes slack overhead before flush()ing), and start the data collection afterwards. Not so flashy, and still depending on the webservers timeout setting, but the user has his response in time.