After isolating my problem, I am testing my API with the following code:
$url = 'http://example.com/api/myendpoint;
print_r(get_headers($url));die();
Sometimes it does works, but sometimes it returns a 404. The link I access simply returns a JSON response.
This started to happen after I reboot my Amazon EC2 server.
If I do in local it seems to work better(but even there sometimes it doesn't work).
Array
(
[0] => HTTP/1.1 200 OK
[1] => Server: nginx/1.10.1
[2] => Content-Type: application/json
[3] => Connection: close
[4] => Cache-Control: private, must-revalidate
[5] => Date: Wed, 02 Nov 2016 14:47:36 GMT
[6] => pragma: no-cache
[7] => expires: -1
[8] => X-Debug-Token: fadeb4
[9] => Strict-Transport-Security: max-age=31536000; includeSubdomains;
)
I tried to do in some online php testers. Same problem.
I thing it's a server configuration problem but I have no idea of how debug that.
Thank you for the help.
UPDATE
I got this data when I see the htmlentities of my request/response
Array
(
[url] => http://example.com/api/myendpoint
[content_type] => text/html
[http_code] => 404
[header_size] => 163
[request_size] => 206
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.00557
[namelookup_time] => 0.004207
[connect_time] => 0.004851
[pretransfer_time] => 0.004874
[size_upload] => 0
[size_download] => 579
[speed_download] => 103949
[speed_upload] => 0
[download_content_length] => 579
[upload_content_length] => 0
[starttransfer_time] => 0.005555
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => ::ffff:XX:XX:XX:XX
[certinfo] => Array
(
)
[primary_port] => 80
[local_ip] => ::ffff:YY.YY.Y.YY
[local_port] => 42744
)
The thing is that the primary ip XX:XX:XX:XX:XX is not my actual ip. It's my old ip, before changing the instance in amazon web-server. This might be causing the problem, but how could I fix it?