Skip to content

Instantly share code, notes, and snippets.

@sgolemon
Created February 9, 2017 20:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgolemon/e95bfc34d34c4f63fa953ee9294ae02c to your computer and use it in GitHub Desktop.
Save sgolemon/e95bfc34d34c4f63fa953ee9294ae02c to your computer and use it in GitHub Desktop.
echo (new Curl('http://example.com'))
->setOpt(Curl::OPT_POSTFIELDS, $postdata)
->setOpt(Curl::OPT_FOLLOWLOCATION, 1)
->perform();
$mh = (new Curl\Multi)
->addHandle($com = new Curl('http://example.com'))
->addHandle($net = new Curl('http://example.net'))
->addHandle($org = new Curl('http://example.org'))
->performUntilComplete();
var_dump($com->getContent(), $net->getContent(), $org->getContent());
@smalyshev
Copy link

smalyshev commented Feb 9, 2017

looks nice 👍

@remicollet
Copy link

+1 :)

@shulard
Copy link

shulard commented Feb 10, 2017

👍 I think this kind of approach can make the cURL adoption easier ! Especially for the multi handler...

@stevehill1981
Copy link

Definitely nicer than the old way of doing things.

@JosephMaxwell
Copy link

+1 would be super nice!

@aepod
Copy link

aepod commented Feb 10, 2017

Great idea, CURL is used way more often than people like to admit.

"When in doubt, CURL it."

Having it OOP will be very nice.

@andrewscaya
Copy link

+1 Nice

@Stelian
Copy link

Stelian commented Feb 11, 2017

To be honest, curl is wrapped by so many user land libraries, I forgot how to actually use the functional approach :) It looks clean and neat, not sure if worth the effort.

@flaupretre
Copy link

Very nice. What about adding this to the curl extension using PCS ? Actually, one of the objectives of PCS is to allow adding an OO layer above function-only extensions without having to write it in C. I cannot dream of a better use case. Less than one hour of work to integrate it. If you send me your scripts, I'd be glad to build a POC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment