4 ms·
One easy way to do multiple http requests in parallel are the curl_muli functions: http://php.net/manual/en/function.curl-multi-init.php http://php.net/manual/
by no_gravity 8y ago
One easy way to do multiple http requests in parallel are the curl_muli functions:
http://php.net/manual/en/function.curl-multi-init.php http://php.net/manual/en/function.curl-multi-init.php
- EZ-E 8y agoThanks, that's one solution if making multiple calls is needed. That was mostly an example though, for example if I wanted to run 3 functions in parallel, I don't find any "easy" and elegant way. Some libraries exist like amp, but it seems a bit heavy handed as the language itself doesn't have great tools for it https://github.com/amphp/amp https://github.com/amphp/amp
- no_gravity 8y agoWhy do you want to run 3 functions in parallel?
- EZ-E 8y agoIt's an example. For example if each of these functions takes about 0.2 seconds to finish, it might make sense to run them in parallel
- moojd 8y agoNeither amphp or reactphp will let you start running blocking functions in parallel out of the box. They basically just provide syntactic sugar for making single-threaded, cooperative multitasking easier by wrapping php's native ability to read/write to sockets asynchronously (or by using pecl extensions.) So you can respond to websocket messages or http requests asynchronously but you're not going to be able to implement anything like a parallel merge sort were you offload work to other threads. Things like general purpose file IO are not easy at the moment either. Amphp might seem a heavy handed because they've taken the monorepo approach. ReactPHP on the other hand has broken everything up into individual components. For example, you can get started with ReactPHP by just pulling in the event loop https://github.com/reactphp/event-loop https://github.com/reactphp/event-loop. All the heavy lifting for the native loop is <200 lines https://github.com/reactphp/event-loop/blob/master/src/StreamSelectLoop.php https://github.com/reactphp/event-loop/blob/master/src/Strea... and the API is tiny as well https://github.com/reactphp/event-loop/blob/master/src/LoopInterface.php https://github.com/reactphp/event-loop/blob/master/src/LoopI...