• <legend id='DVzHo'><style id='DVzHo'><dir id='DVzHo'><q id='DVzHo'></q></dir></style></legend>

      <tfoot id='DVzHo'></tfoot>
    1. <i id='DVzHo'><tr id='DVzHo'><dt id='DVzHo'><q id='DVzHo'><span id='DVzHo'><b id='DVzHo'><form id='DVzHo'><ins id='DVzHo'></ins><ul id='DVzHo'></ul><sub id='DVzHo'></sub></form><legend id='DVzHo'></legend><bdo id='DVzHo'><pre id='DVzHo'><center id='DVzHo'></center></pre></bdo></b><th id='DVzHo'></th></span></q></dt></tr></i><div id='DVzHo'><tfoot id='DVzHo'></tfoot><dl id='DVzHo'><fieldset id='DVzHo'></fieldset></dl></div>

      <small id='DVzHo'></small><noframes id='DVzHo'>

        • <bdo id='DVzHo'></bdo><ul id='DVzHo'></ul>

        PHP cURL 实时代理(流文件)

        PHP cURL Realtime proxy (stream file)(PHP cURL 实时代理(流文件))
        <i id='p6bx9'><tr id='p6bx9'><dt id='p6bx9'><q id='p6bx9'><span id='p6bx9'><b id='p6bx9'><form id='p6bx9'><ins id='p6bx9'></ins><ul id='p6bx9'></ul><sub id='p6bx9'></sub></form><legend id='p6bx9'></legend><bdo id='p6bx9'><pre id='p6bx9'><center id='p6bx9'></center></pre></bdo></b><th id='p6bx9'></th></span></q></dt></tr></i><div id='p6bx9'><tfoot id='p6bx9'></tfoot><dl id='p6bx9'><fieldset id='p6bx9'></fieldset></dl></div>

        <legend id='p6bx9'><style id='p6bx9'><dir id='p6bx9'><q id='p6bx9'></q></dir></style></legend><tfoot id='p6bx9'></tfoot>
            <bdo id='p6bx9'></bdo><ul id='p6bx9'></ul>

              <tbody id='p6bx9'></tbody>

                <small id='p6bx9'></small><noframes id='p6bx9'>

                • 本文介绍了PHP cURL 实时代理(流文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目前我有一个如下所示的脚本:

                  Currently I have a script like the following:

                  <?php
                  $filename = "http://someurl.com/file.ext";
                  header('Content-Type: application/octet-stream');
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$filename);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
                  $data=curl_exec($ch);
                  curl_close($ch);
                  echo $data;
                  ?>
                  

                  问题是服务器在下载整个文件后才发送响应.我想让它像流"一样工作,在下载文件时发送数据块作为响应.

                  The problem is that the server just send the response after download the whole file. I want to make it work like a "stream", sending chunks of data as response while the file is downloaded.

                  用 PHP 和 cURL 可以实现吗?

                  Is that possible to achieve with PHP and cURL?

                  推荐答案

                  这是可能的.您可以使用 curl 选项 CURLOPT_WRITEFUNCTION 指定一个回调,您将在其中接收数据块,以便在 curl 下载文件时将它们直接发送到客户端.

                  It's possible. You can use the curl option CURLOPT_WRITEFUNCTION to specify a callback where you'll receive chunks of data so you can send them directly to the client as curl downloads the file.

                  <?php
                  
                  $filename = "http://someurl.com/file.ext";
                  header('Content-Type: application/octet-stream');
                  header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$filename);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
                  curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
                      echo $data;
                      return strlen($data);
                  });
                  curl_exec($ch);
                  curl_close($ch);
                  

                  这篇关于PHP cURL 实时代理(流文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <small id='kzl8F'></small><noframes id='kzl8F'>

                    • <legend id='kzl8F'><style id='kzl8F'><dir id='kzl8F'><q id='kzl8F'></q></dir></style></legend>

                      <tfoot id='kzl8F'></tfoot>

                          • <bdo id='kzl8F'></bdo><ul id='kzl8F'></ul>
                            <i id='kzl8F'><tr id='kzl8F'><dt id='kzl8F'><q id='kzl8F'><span id='kzl8F'><b id='kzl8F'><form id='kzl8F'><ins id='kzl8F'></ins><ul id='kzl8F'></ul><sub id='kzl8F'></sub></form><legend id='kzl8F'></legend><bdo id='kzl8F'><pre id='kzl8F'><center id='kzl8F'></center></pre></bdo></b><th id='kzl8F'></th></span></q></dt></tr></i><div id='kzl8F'><tfoot id='kzl8F'></tfoot><dl id='kzl8F'><fieldset id='kzl8F'></fieldset></dl></div>

                              <tbody id='kzl8F'></tbody>