惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 尘梦

calude code 2.188 根据cli.map还原 centos6 安装gcc 多版本 自定义编译bulma 神通mysql模式转 mysql ai数学书籍 chromedriver 网络安全渗透测试写法 编译php需要的扩展 python 合并同列数据 组合 新的excel - 尘梦 vue table 表格记录选中 - 尘梦 linux wktohtmlpdf 结合/tmp路径 无法创建问题 c语言开发 php扩展 sm4 macos php 如何链接神通数据库aci layui table tr a标签倒计时 操作 刷新以后继续倒计时 使用c# 开发 php的com组件 世界级地图数据处理 及 联动效果 php 结合pcntl_fork导出excel数据 使用 python 部署chatglm2b macos 下连接php 人大金仓pdo_kdb问题
php curl 多次发送
尘梦 · 2023-07-24 · via 博客园 - 尘梦

public function curls()
    {
        $urls = "http://wyh.li/review/save_all_agree?act=do";
       
        foreach (range(1, 100) as $vals) {
            $expert_id = $vals;
            $mulcurl[] = $this->singleCurl($urls, $expert_id);
        }

        $data = $this->multiCurl($mulcurl);

        var_dump($data);
    }


    public function singleCurl($url, $expert_id = 0)
    {
        $data['is_all_agree'] = 1;
        $data['list_type'] = 3;
        $data['expert_id'] = $expert_id;


        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        // $output = curl_exec($curl);

        // var_dump($output);
        return $curl;
    }

    //多进程curl
    public function multiCurl($ch_arr)
    {
        $mh = curl_multi_init();
        foreach ($ch_arr as $k => $c) {
            curl_multi_add_handle($mh, $ch_arr[$k]);
        }
        $active = null;
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);

        while ($active && $mrc == CURLM_OK) {
            usleep(50000);
            if (curl_multi_select($mh) != -1) {
                do {
                    $mrc = curl_multi_exec($mh, $active);
                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
        }

        foreach ($ch_arr as $k => $v) {
            if (curl_error($ch_arr[$k]) == '') {
                $res[$k] = json_decode(curl_multi_getcontent($ch_arr[$k]), true);
            }
            curl_close($ch_arr[$k]);
        }
        curl_multi_close($mh);
        return $res;
    }