lorenw — 2012-02-09T14:48:02-05:00 — #1
Hi All, this is for a project that I've inherited. The site has a three page questionnaire, each time a form is filled out data goes into the database.
After the first page/form is filled out, I need a script that will sleep 7 minutes and then query the database and get all of the info that was submitted and then send what data got entered off to a lead tracking website via cURL.
Obviously if I put sleep in the main signup script it will wait 7 minutes for the next page to load.
I'm thinking of placing the query and cURL in a separate script and caling it using touch, something like,
Something about this seems roundabout to me, does anyone have any thoughts or opinions on how to do this?
cups — 2012-02-10T04:36:23-05:00 — #2
Just to clarify, do the 3 forms get saved to the db individually and on successful completion of the final form (3) the form contents should be sent on?
Or are you really saying as long as form1 is filled in, even if the rest of the operation is abandoned by the user, you then wait and send it on?
lorenw — 2012-02-10T08:21:39-05:00 — #3
The three forms get saved individually and people can bail out at any stage. I may get one page or all three pages.
In any event I need to send what data I did get to the lead tracking website.
ultra1 — 2012-02-10T09:04:28-05:00 — #4
I am thinking you may instead use a cron to start a script every couple of munites. That script will query database and select all records that have been created 7 minutes ago, send then out to some API, then mark them as 'processed' in the database.
All you need to do is to make sure there is a 'created_time' and 'processed' fields in the leads table.
No need to use sleep at all for something like this
lorenw — 2012-02-10T11:16:42-05:00 — #5
I thought about a cron but if the cron runs right after the first form is submitted that is all the data I get.
This has to be a timer based on when the first form gets submitted.
As always all input is appreciated.
lorenw — 2012-02-10T12:03:32-05:00 — #6
OK touch is not the answer, it creates files with the name "email@example.com&id=777".
I need some way to pass a query string to a script that will run in the background.
lorenw — 2012-02-10T12:41:14-05:00 — #7
I tried cURL but once again I get a 7 second delay, here is the snippet.
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result= curl_exec ($ch);
I thought that cURL without "CURLOPT_RETURNTRANSFER, 1" would just post the data and not wait for the sleeper script to finish executing.
There must be a simple answer.
cups — 2012-02-10T13:58:40-05:00 — #8
If I am right in thinking, you can link all the 3 forms with some token like a user id.
How about you had a table which records the events of each form being saved.
id_ref - a UID
form_1 - a timestamp
form_2 - a timestamp
form_3 - a timestamp
sent - BOOL 1/0
Then you can tell cron every minute say, to call a script which polls that table for rows which have a form1 time of > 7 minutes but < 8 minutes AND a sent of 0
OR a form1 time as above and anything in form3...
sent is YAGNI) actually then look up that user id_ref and pass to curl?
Something like that?
lorenw — 2012-02-10T17:50:15-05:00 — #9
Thanks for the ideas, trying to get php to do something in the background turned out to be a lot more challenging than I thought.
Bash to the recue,
exec("nohup nice php -q ./sleeper.php -f filename -t filetype > /dev/null & echo $!");
Bash at first was not executing in the background. Add the trimmings like so and it works a treat.
Thanks again, hope this helps someone else.