-1

I am working with an api from a gateway that I want to send a series of replies to a POST request from the other end.

It sends notification that ideas are in the remote queue but this script must respond by going and getting the queue data (rather than it coming in the POST)

  1. So the PHP script receives the POST, it then does some user data lookups and checks locally.
  2. Then return a header status 200 to the POST request with empty body.
  3. Then construct a following GET request to get the rest of the data.
  4. Process the queue data for payment
  5. Return 404 termination at any point the process fails.

How can I send in essence multiple output "messages" back from a single php script, while not terminating it?

First a header status 200 with empty body and the I can still do the get request.

Or am I thinking of this the wrong way. I wanted to do it all GET and POST in Gulp and change the script that I was given but I can't see how to send a response while I know how to receive with it.

Thanks.

tristanbailey
  • 4,427
  • 1
  • 26
  • 30
  • Or how can I mock this to test the other end I don't have access to? – tristanbailey Aug 13 '15 at 14:13
  • By just sending data, your server will be responding with `200` since it's the default HTTP status when providing a valid response. As for sending GET requests back to the endpoint, you just use cURL within PHP. You're not sending pages, you're sending requests from your server this way. – sjagr Aug 13 '15 at 14:17
  • "construct a second get"? who constructs this get? you? or the "other end point"? – Marc B Aug 13 '15 at 14:17
  • Construct, I mean based on the POST +db call the url get parmas will be concat together. – tristanbailey Aug 13 '15 at 14:19
  • The issue is if I the script sends a header(etc..) back it does not execute that statement, until the get curl call. so they dont run it the right order – tristanbailey Aug 13 '15 at 14:20
  • Maybe I just echo ' '; instead and header goes on for the ride for free – tristanbailey Aug 13 '15 at 14:20
  • 1
    try to look at this, using ob_end_clean http://stackoverflow.com/questions/3833013/continue-php-execution-after-sending-http-response – Daniel Krom Aug 13 '15 at 14:49

1 Answers1

1

I spoke to @ramsey on another channel and he was kind enough to give me some pointers for the answer.

<?php
// Return our response as quickly as possible.
header('Connection: close');

ob_start();
header('HTTP/1.0 200 OK');
ob_end_flush();
flush();
// This immediately sends our response to the client

// Now, you can do all your other processing.

Adding the output buffering seemed to help

tristanbailey
  • 4,427
  • 1
  • 26
  • 30