I want to have an HTTP GET request sent from PHP. Example:
http://tracker.example.com?product_number=5230&price=123.52
The idea is to do server-side web-analytics: Instead of sending tracking information from JavaScript to a server, the server sends tracking information directly to another server.
Requirements:
The request should take as little time as possible, in order to not noticeably delay processing of the PHP page.
The response from the
tracker.example.com
does not need to be checked. As examples, some possible responses fromtracker.example.com
:200: That's fine, but no need to check that.
404: Bad luck, but - again - no need to check that.
301: Although a redirect would be appropriate, it would delay processing of the PHP page, so don't do that.
In short: All responses can be discarded.
Ideas for solutions:
In a now deleted answer, someone suggested calling command line curl from PHP in a shell process. This seems like a good idea, only that I don't know if forking a lot of shell processes under heavy load is a wise thing to do.
I found php-ga, a package for doing server-side Google Analytics from PHP. On the project's page, it is mentioned: "Can be configured to [...] use non-blocking requests." So far I haven't found the time to investigate what method php-ga uses internally, but this method could be it!
In a nutshell: What is the best solution to do generic server-side tracking/analytics from PHP.
curl
from PHP. If there was a link, I believe it can be removed.curl
is part of the standard UNIX web server tool chain (curllib
is accessible from PHP, by the way). In addition, once I find the time, I would like to look into php-ga and investigate the method that is uses for non-blocking requests. But maybe someone on Stack Overflow knows this off the top of his head? – Afternooncurl
in it. But if I do so, then the method in the linked question could be one part of the solution. – Afternoonstream_set_blocking
. Perhaps you add it to your answer? – Afternoon