I have also voted that answer down, so I´ll take the chance to explain.
There are several ways to do a POST request in PHP with the functions, methods and tools deeply integrated into PHP.
You could use curl
, http_post_fields
or file_get_contents
in combination with stream_context_create
like it was pointed out in the answers. Most people obviously recommended curl
which should get the job done.
Now you come along and throw guzzle into the ring. Well, that thing seems to be well-known around the PHP community, I just heard about it yesterday, but you maneuver yourself in a dependency on guzzle and its functions.
We all should have heard of how a simple left pad broke the world. Of course, PHP works different etc. but I, maybe just for myself, don´t like to include external packages, libraries or whatever.
Yeah, that obviously makes me slower when developing, I sometimes may have to reinvent the wheel, but as I am not doing this full-time, I have no big problem with that.
On the other hand building things from the ground enables me to check all of the code, that I have written with my own style, commented like I felt the need to, and see how I got my head around things.
Yes, you can throw a bunch of guzzle in there, hope that it works, read their docs, whatever. But if it breaks, you´ll never know why, have to wait for their bugfixes, trust in their security patches and more.
And for what? Doing a post request which you could do on three different ways with the stuff that is built into Vanilla PHP? I don´t think this is something you should do as a programmer/developer.
We should define ourselves by using built-in ways as often and as good as possible and get our head around problems and how things work instead of linking magical libraries for easy tasks like this.
That´s why I downvoted your answer.