File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ require __DIR__ . '/../vendor/autoload.php ' ;
3
+
4
+ use Curl \ArrayUtil ;
5
+ use Curl \MultiCurl ;
6
+
7
+ $ proxies = array (
8
+ 'someproxy.com:9999 ' ,
9
+ 'someproxy.com:80 ' ,
10
+ 'someproxy.com:443 ' ,
11
+ );
12
+ $ max_retries = 3 ;
13
+
14
+ $ multi_curl = new MultiCurl ();
15
+ $ multi_curl ->setProxyType (CURLPROXY_SOCKS5 );
16
+ $ multi_curl ->setProxies ($ proxies );
17
+
18
+ $ multi_curl ->setRetry (function ($ instance ) use ($ proxies , $ max_retries ) {
19
+ if ($ instance ->retries < $ max_retries ) {
20
+ $ new_random_proxy = ArrayUtil::arrayRandom ($ proxies );
21
+ $ instance ->setProxy ($ new_random_proxy );
22
+ return true ;
23
+ } else {
24
+ return false ;
25
+ }
26
+ });
27
+
28
+ $ multi_curl ->addGet ('https://httpbin.org/ip ' );
29
+ $ multi_curl ->addGet ('https://httpbin.org/ip ' );
30
+ $ multi_curl ->addGet ('https://httpbin.org/ip ' );
31
+
32
+ $ multi_curl ->complete (function ($ instance ) {
33
+ echo
34
+ 'curl id ' . $ instance ->id . ': ' . "\n" .
35
+ '- ip: ' . $ instance ->response ->origin . "\n" .
36
+ '- proxy: ' . $ instance ->getOpt (CURLOPT_PROXY ) . "\n" .
37
+ '- url: ' . $ instance ->effectiveUrl . '' . "\n" .
38
+ '' ;
39
+ });
40
+
41
+ $ multi_curl ->start ();
You can’t perform that action at this time.
0 commit comments