0

I have a form that sends a simple http post to a PHP page. The PHP code processes the post which results in pulling a JSON string from a url, parsing it, and then sending a bunch of emails. All the code is on one page and works as intended.

The thing that bugs me is waiting for all the emails to get sent, and finally receiving the HTTP post response. What I'd like to do is separate the initial post from the JSON string processing. In other words, close the post session immediately, getting a simple "Done" and let the PHP JSON-processing code do its thing.

I'm new at PHP so any advice will be helpful.

johnwhitney
  • 93
  • 1
  • 3
  • 12
  • Now that you have stated what you want to do, you need to tell us the problem you're facing. What exactly is the question? – phant0m Aug 01 '11 at 16:58
  • @phant0m: how to send "ajax" request from php script (I mean to run php function asynchronously) – genesis Aug 01 '11 at 16:58

3 Answers3

0

You're looking for fsockopen() function

genesis
  • 50,477
  • 20
  • 96
  • 125
  • Explain? (don't quite see how it's relevant) – Nightfirecat Aug 01 '11 at 17:38
  • No, fsockopen does not seem to be a solution. As stated my PHP code is working as-is. I simply need the http post part separate from the JSON processing part. I do not want to wait around the the processing to complete. It's almost like I need two PHP pages. One is the receiver of my command by http post and the other takes the command and processes the JSON data on the server-side - as a background process. – johnwhitney Aug 01 '11 at 18:13
  • I think I need exec() in the PHP page that accepts my http post. I then need to pass the posted strings to another PHP page using exec(). Any ideas how to do this? – johnwhitney Aug 01 '11 at 18:59
0

The best option would be to use a message queue like Redis(has blpop/brpop commands) . Luckily redistogo offers free plans. There should be more than enough information on the web about this(Google).

Second best option would be to use asynchronous calls

Community
  • 1
  • 1
Alfred
  • 60,935
  • 33
  • 147
  • 186
0

I would add the mails that have to be sent to a database and setup a cron job to periodically send all mails that have not been sent yet.

jeroen
  • 91,079
  • 21
  • 114
  • 132