PHP – Handling Recurring cURL POST Requests

PHP

I've basically came here for some advise based on my criteria,

The application I'm trying to build is built completely from an API. It's like a "marketplace bidding" application, what I'm trying to accomplish is an "Auto bidding" function, but for this to happen it will have to send a cURL POST request every 3 seconds based on criteria given, then return the JSON result for me to handle server side,

I'd basically like a direction on what would be the best way to handle this kind of idea, I got told something called "polling" would work but I've never heard of it. Initially the idea is as provided below

  1. Load set page "bid.php"
  2. Enter certain criteria
  3. Click submit as to which an "Ajax" request of some sort would start
  4. The recurring cURL request would be activated through the Ajax.
  5. Display the data back from the cURL request every 3 seconds via Javascript.

I'm not initially asking for the work to be given to me, I'm just asking the professionals as to which they recon would be the best way I can do this task.

Best Answer

You could have one page, let's call it auto_bid.php. This file could be a basic php file that receives a string through GET or POST, does a curl to wherever and receives the JSON response. You could process the response and generate your own response.

Your bid.php file could have the input box and button. When the user enters criteria and clicks the button, it would make a call to a javascript function that is set on a recursive 3 second timeout loop (settimeout() perhaps), and that function can use a javascript or jquery ajax call (jquery has a built in method) passing the string, to auto_bid.php.

The response from auto_bid.php that you set up could be a JSON string that you can have js handle and adjust the bid.php html to display "auto bidded $XX". Then it would attempt a bid again and display again. You could also have auto_bid.php respond with HTML instead, and when you receive it through your ajax call, just dump it into a DIV or something.

Related Topic