0

I'm simply trying to do PUT/DELETE requests in my PHP application, but after the first 5 requests, the data is lost.

I've reduced the code to this to illustrate the issue:

index.php

$h = fopen('php://input', 'r');
var_dump(fread($h, 1024));
die();

CLI input

curl -X PUT http://cms.dev.com -d '{"foo":"bar"}'

So, for the first 5 times I run that, I get:

string(13) "{"foo":"bar"}"

Then, from the 6th onwards, I get:

string(0) ""

I'm running PHP Version 5.6.0beta1 and Apache/2.2.26, installed on OSX 10.9.3 via Mac Ports.

POST works fine.

EDIT It might be worth noting this can be replicated on 2 other colleague's MacPorts setups, but can't on MAMP, which seems to act correctly.

Does anyone have ideas? It's driving me crazy!

Thanks, Todd

Toddish
  • 516
  • 2
  • 12
  • Why do you want to use PUT rather than POST? I understood that PUT was designed for adding / updating a resource with a specified identifier, but you don't seem to be using one in your example. See http://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request. – Squig May 27 '14 at 16:11
  • It's for a backbone.js application, I'm updating a user. The code above is just to replicate the issue. – Toddish May 27 '14 at 16:22
  • So, are you providing an identifier with your PUT request in the "real" code? I know this is sounding less and less relevant (given your edit about it working on MAMP but not via MacPorts), but it may still be a factor. – Squig May 28 '14 at 17:43

2 Answers2

1

I cannot reproduce this using the built-in webserver, which might indicate an interaction between apache and php.

Try running :-

php -S localhost:8001

in one terminal and

for n in `seq 1 100`; do curl -X PUT http://localhost:8001 -d '{"foo":"bar"}'; done

in another - see if it's limited to php or at the mod_php level.

My testing is on a linux box with 5.4.9 fwiw.

Martyn R
  • 151
  • 1
  • 2
  • Cheers for the help. This always returns as an empty string, doesn't even give me the 5. – Toddish May 27 '14 at 16:29
  • Curl activities can be quite slow, even on localhost. and usually a write/put operation is not buffered. Are you waiting for the prior cURL operation to complete before starting the next? BTW: the line: php -S localhost:8001 results in an immediate error message on my linux box, and the man page shows no '-S' option. maybe it should be '-s' which echos any HTML syntax highlited source. However, that also fails, saying it cannot open localhost:8001 – user3629249 May 28 '14 at 07:22
0

Upgrading to php 5.6beta3 fixed the issue.

Must have been a bug in php 5.6beta1!

Hopefully this'll help someone else :)

Toddish
  • 516
  • 2
  • 12