Coder Social home page Coder Social logo

imroychen / request Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 37 KB

Support Http requests such as Get/Post/Put/Upload/download. Single-threaded and multi-threaded seamless switching. This package is an encapsulation of the "CURL" library, which can easily implement various network requests, API requests, etc. Single-threaded and multi-threaded concurrent requests can be seamlessly switched at any time

PHP 100.00%
curl curl-multi multi-threaded-request php-request post request

request's People

Contributors

imroychen avatar kaixingwang avatar roy2chen avatar

Stargazers

 avatar

Watchers

 avatar

request's Issues

Helper的问题

Helper::post的时候,传的post的数据会丢失,private function _processCfg($cfg,$idx){里面,应该为`
private function _processCfg($cfg,$idx){
$cfg = array_merge($this->_defaultCfg(),$cfg);

    if(isset($cfg['postfields']) && $cfg['postfields'] === 0) {
        $cfg['post'] = 1;
        $cfg['postfields'] = '';
    }elseif ( isset($cfg['post']) && !empty($cfg['post']) && !isset($cfg['postfields']) ) {
        $post = /*is_array($cfg['post']) ? http_build_query($cfg['post']) : */$cfg['post'];
        $cfg['post'] = 1;
        $cfg['postfields'] = $post;
    }

    //下载文件使用
    if(isset($cfg['to_file']) && $cfg['to_file']){//to_file
        $f = is_bool($cfg['to_file'])?($this->_tmpPath.uniqid().mt_rand(100,999)):$cfg['to_file'];
        $fp = fopen ($f, 'w+');
        unset($cfg['returntransfer']);
        $cfg['file'] = $fp;
        $this->_downloadToFiles[$idx] = [$f,$fp];//记录该任务存储路径,留完成后关闭 和重试的时候使用
    }elseif ( isset($this->_downloadToFiles[$idx]) && $this->_downloadToFiles[$idx][0] ){
        //重试的时候 $cfg['to_file']已经被删除
        $fp = fopen ($this->_downloadToFiles[$idx][0] , 'w+');
        $this->_downloadToFiles[$idx][1] = $fp;
        $cfg['file'] = $fp;
    }

    if(isset($cfg['@transfer']) && !empty($cfg['@transfer'])){//走中转代理包装
        $url = $cfg['@transfer'];
        unset($cfg['@transfer']);

        $cfg = [
            'post'=>1,
            'postfields'=>http_build_query(['cfg'=>json_encode($cfg)]),
            'url'=>$url
        ];
    }

    $this->_fire('item_before_request',[$this->_decodeId($idx),$cfg]);
    $conn = curl_init();
    foreach ($cfg as $k => $v) {
        $k = 'CURLOPT_' . strtoupper($k);
        if (defined($k)) {
            curl_setopt($conn, constant($k), $v);
        }
    }
    return $conn;
}`

返回结果有问题

public function getResult(){ $res =[]; $this->_call(function ($idx,$request,$_resItem)use(&$res){ $res[$idx]=[ 'result' => $this->getContent($_resItem), 'info' => $this->getInfo($_resItem), ]; }); return $res; }
这一行少了一个&,应该是&$res

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.