Why does CURL behave strangely

How exactly would Javascript differentiate between:

This is good return data


PHP Error: Unexpected $end in file

? They’re both just strings.

If the page returns a status code that is not 200, the engine on the requesting end CAN react to it, but only after the response is received.

I just dont see what you’re trying to say should happen. Let me lay it out step by step, and you can tell me where you think something magically different happens.

  1. Client A Request is sent to endpoint.php to Server B.
  2. That request goes through the internet.
  3. B’s HTTP server (apache, nginx, etc) receives the request.
  4. B starts the PHP engine, and hands the engine the information received in the request.
  5. PHP parses endpoint.php, with the information received.
  6. PHP generates an error.
  7. B’s HTTP server takes whatever HTTP status code PHP tells it to use, and whatever response body is there, and responds to A with it.
  8. The response goes through the internet.
  9. A receives the response, and parses it.
  10. A can see the HTTP status code, and react to it (200, good, 400, bad, etc).

When you use CURLOPT_RETURNTRANSFER with a boolean value false, PHP internally converts it to an integer 0 because CURL generally expected to be integers. However, 0 still indicates that CURL should return the output of the request.

On the other hand, when you use a string value 'false', PHP consider it as a string and passes it directly to CURL. Since 'false' is not an integer 0, CURL interprets it as a command to not return the output.

That’s… not true. RETURNTRANSFER is one of many parameters that expects a boolean.

1 Like


The answer and guidance provided by @m_hutley is the right way to is use it. With very strong points as he did outlined.

Thanks alot, have written to the awarders to retrieve the peaceful language award given to JavaScript in an undisclosed location.

My first assertion was wrong, the cause of ajax call returning empty is because there is an error in the host server preventing ajax from even running