关于curl批量验证代理的一个问题
curl多线程 代理 验证 proxy curl 多线程 代理 验证
问题是这样的: 我用curl多线程来验证代理....for($i=0;$i<$maxconn;$i++) /*循环加入句柄*/ { add_curl_handle($mh,$proxyarr[$linknum],$limittime); /*添加批处理的url*/ $linknum++; } do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) /*处理下一个响应*/ { if (curl_multi_select($mh) != -1) /*选择是响应的句柄*/ { do { $mrc = curl_multi_exec($mh, $active); /*返回活动的链接*/ } while ($mrc == CURLM_CALL_MULTI_PERFORM); if ($mhinfo = curl_multi_info_read($mh)) /*返回活动的句柄*/ { $chinfo = curl_getinfo($mhinfo['handle']); /*获得请求的数据*/ if($chinfo['http_code']==200) /*判断是否为200状态*/ {__________________________________________________________________________现在重点是这里应该怎么写才能获取到这个验证成功的代理?这里的语句应该怎么写,好像curl_getinfo里面没有获取句柄使用的代理的功能..求高手指教.__________________________________________________________________________ } } curl_multi_remove_handle($mh, $mhinfo['handle']); /*移除句柄*/ curl_close($mhinfo['handle']); /*关闭请求*/ if(add_curl_handle($mh,$linkarray[$linknum],$limittime)&&$linknum<count($linkarray)) /*判断添加下一个句柄*/ { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); $linknum++; } } }
回复讨论(解决方案)
有木有朋友在呀....在线等了10积分争了 貌似还没有回音...
你的 $proxyarr[$linknum] 是如何赋值的?
一般宜做成通过代理访问同一个网站(不知道你是否是这么做的)
这样只要某个 $mh 项能正常返回,就表示对应的代理是正确可用的
CURLOPT_PROXY 设置代理地址和端口
CURLOPT_PROXYUSERPWD 设置代理的用户名和口令
你也可以用
CURLOPT_HTTPPROXYTUNNEL、CURLOPT_PROXYAUTH、CURLOPT_PROXYPORT、CURLOPT_PROXYTYPE
做细节设置
你的 $proxyarr[$linknum] 是如何赋值的?
一般宜做成通过代理访问同一个网站(不知道你是否是这么做的)
这样只要某个 $mh 项能正常返回,就表示对应的代理是正确可用的
CURLOPT_PROXY 设置代理地址和端口
CURLOPT_PROXYUSERPWD 设置代理的用户名和口令
你也可以用
CURLOPT_HTTPPROXYTUNNEL、CURLOPT_PROXYAUTH、CURLOPT_PROXYPORT、CURLOPT_PROXYTYPE
做细节设置 是这样的 有关代理设置,参数设置我都已经做好了..现在就是在逐一获取多线程单一句柄的时候 获取改句柄到底使用的是那个代理 如果这个句柄返回的是200代码 我就可以吧这个代理保存下来.. 现在问题是没办法获取到这个句柄使用的代理
一般宜做成通过代理访问同一个网站(不知道你是否是这么做的)
这样只要某个 $mh 项能正常返回,就表示对应的代理是正确可用的 现在还是如果发现这个代理是可用的 ,,那么应该如何获取这个代理呢 因为是批量验证 所以每个句柄使用的都是不同的代理..网站倒是一样的
木有人在咯...版主大大呢
你的 $proxyarr 不是顺序加入 $mh 的吗?
嗯,你的后两节写的有些古怪
我一般这样写:
$mh = curl_multi_init();
//加入单个的curl
foreach ($urls as $i => $url) {
$conn[$i] = curl_init($url);
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle($mh, $conn[$i]);
}
//等待全部完成
do {
curl_multi_exec($mh, $active);
}while($active);
//处理每个curl的返回
foreach ($urls as $i => $url) {
$info = curl_getinfo($conn[$i]);//这里就是了
curl_close($conn[$i]);
}
$conn 和 $urls 是一一对应的
//处理每个curl的返回
foreach ($urls as $i => $url) {
$info = curl_getinfo($conn[$i]);//这里就是了
curl_close($conn[$i]);
}
$conn 和 $urls 是一一对应的 明白了,, 这样子也是可以的,,其实是做法不一样 我是在多线程并发的时候等待完成的句柄小小一有消息就把好的代理输出来..想这样验证的代理一般都是几千个的.如果用你的做法,可能要把这几千个代理验证完了才能输出好的代理 ,时间太长了..还有一个地方不一样就是 我限制了并发的句柄的数量 只有等一个句柄完成了,才把下一个句柄添加进去..
还有木有人在呀 ,,,版主大大一个人忙不过来额 求各位来帮帮忙...
嗯,我不喜欢纸上谈兵
快与不快要做了才知道
嗯,我不喜欢纸上谈兵
快与不快要做了才知道 现在没有纸上谈兵呀...- - 在解决这个问题我先这么做吧..效果出来再继续问你 可以私信给我你的QQ么
.
通过curl好像没有好的方式,你为什么不在请求的url是多传递一个参数,参数的内容就是$linknum,在获取的时候可以通过获取
$chinfo = curl_getinfo($mhinfo['handle']);
$chinfo['url']肯定就会带有这个$linknum
而你通过$linknum一定知道代理是什么
通过curl好像没有好的方式,你为什么不在请求的url是多传递一个参数,参数的内容就是$linknum,在获取的时候可以通过获取
$chinfo = curl_getinfo($mhinfo['handle']);
$chinfo['url']肯定就会带有这个$linknum
而你通过$linknum一定知道代理是什么 这个随便加一个参数会不会页面验证非法的参数二初二难题呢??
通过curl好像没有好的方式,你为什么不在请求的url是多传递一个参数,参数的内容就是$linknum,在获取的时候可以通过获取
$chinfo = curl_getinfo($mhinfo['handle']);
$chinfo['url']肯定就会带有这个$linknum
而你通过$linknum一定知道代理是什么 不过这也是个好方法...的确可行的..
过程有些波折 不过最后还是解决了 ..谢谢斑竹 还有下面"hnxxwyq"

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.
