dongshetao1814 2014-10-29 00:21
浏览 92
已采纳

PHP用guzzle阻止对远程Web服务的请求

i'm trying to execute a request to a web service to download large files to my server. My web application is in laravel 4 and i'm using guzzle to make the request.

The problem is, after starting the file download from the remote service, i can't execute any request to my app until the download response is complete.

Here is a example of my code:

    public function download($id, $url, $filename)
    {
        // some data for request

        $request = $httpClient->get($downloadFileUrl, array(
               'future' => true, 
               'cookies' => true, 
               'save_to' => $filename
               )
         );

         return $cookieRequest;
     }

In the past i use exec to start curl or wget scripts to downlaod the files to the server. But i would like to have more control over the requests and responses.

Any help would be appreciated,

Thanks

  • 写回答

1条回答 默认 最新

  • dscuu86620 2014-10-29 01:05
    关注

    You could use work queues to run the download in the background:

    Queue::push(function($job)
    {
        $request = $httpClient->get($downloadFileUrl, array(
            'future' => true, 
            'cookies' => true, 
            'save_to' => $filename
        ));
    
        $job->delete();
    });
    

    Here's a good article on how to Setup Laravel with Beanstalkd, but you could also use others like IronMQ, Amazon SQS, Redis.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线