Most probably didn’t even know that Cake internally switched from HTTP/1.0 (cake1.x) to HTTP/1.1 (cake2.x). While most changes regarding the new specification are great, they can also break existing functionality, of course.
With the new protocol there are a few new features that can be used now in Cake:
Conditional view rendering is one of the new features possible with HTTP/1.1 and a few new headers available now.
New status codes
Interesting is the new code
410 (Gone) which can be “used when a resource has been removed permanently from a server, and to aid in the deletion of any links to the resource”.
Of course, it has a lot of other improvements over the old protocol, as well. You can read about them here.
In an external php file we need to get some data. This script is quite old and simply gets some serialized data from the main server:
$content = file_get_contents('http://mainserverurl.com/some/action/');
Now, with the upgrade to 2.x those scripts suddently take 15 seconds. We wondered what could be the cause of the issue – discovering that in HTTP/1.1 “all connections are considered persistent unless declared otherwise”.
According to this question and its answer here it is possible to still use file_get_contents:
$context = stream_context_create(array('http' => array('header' => 'Connection: close\r\n'))); $content = file_get_contents('http://mainserverurl.com/some/action/', false, $context);
You manually tell the server to close the connection after the retrieval.
In our case, and since the script was also used by servers we do not directly control, we had to make our cake app send the appropriate header:
// inside our action: $this->response->header('Connection: close');
You manually tell the client to close the connection after the retrieval.
So what do we learn from that?
Better don’t use unintelligent php methods in favor of curl or other approaches. But sometimes you are outside Cake (and therefore not able to use the HttpResponse class) and maybe not even able to use curl. Then it helps if you know how can get it working again, after all.