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

    <legend id='MeqII'><style id='MeqII'><dir id='MeqII'><q id='MeqII'></q></dir></style></legend>
    • <bdo id='MeqII'></bdo><ul id='MeqII'></ul>
    1. <tfoot id='MeqII'></tfoot>

      1. 处理一个长度为 3000 万个字符的字符串

        时间:2023-05-21

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

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

              1. <legend id='K0Kkf'><style id='K0Kkf'><dir id='K0Kkf'><q id='K0Kkf'></q></dir></style></legend>
                  <tbody id='K0Kkf'></tbody>
                <tfoot id='K0Kkf'></tfoot>
                  <bdo id='K0Kkf'></bdo><ul id='K0Kkf'></ul>
                  本文介绍了处理一个长度为 3000 万个字符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在从另一台服务器下载一个 CSV 文件作为来自供应商的数据源.

                  I am downloading a CSV file from another server as a data feed from a vendor.

                  我正在使用 curl 来获取文件的内容并将其保存到一个名为 $contents 的变量中.

                  I am using curl to get the contents of the file and saving that into a variable called $contents.

                  我可以很好地到达那部分,但是我尝试通过 进行爆炸以获取行数组,但它失败并显示 'out of内存错误.

                  I can get to that part just fine, but I tried exploding by and to get an array of lines but it fails with an 'out of memory' error.

                  echo strlen($contents) 大约有 3050 万个字符.

                  I echo strlen($contents) and it's about 30.5 million chars.

                  我需要操作这些值并将它们插入到数据库中.我需要做什么来避免内存分配错误?

                  I need to manipulate the values and insert them into a database. What do I need to do to avoid memory allocation errors?

                  推荐答案

                  PHP 因内存不足而窒息.不要让 curl 用文件内容填充 PHP 变量,而是使用

                  PHP is choking because it's running out memory. Instead of having curl populate a PHP variable with the contents of the file, use the

                  CURLOPT_FILE
                  

                  改为将文件保存到磁盘的选项.

                  option to save the file to disk instead.

                  //pseudo, untested code to give you the idea
                  
                  $fp = fopen('path/to/save/file', 'w');
                  curl_setopt($ch, CURLOPT_FILE, $fp);
                  curl_exec ($ch);
                  curl_close ($ch);
                  fclose($fp);
                  

                  然后,一旦文件被保存,而不是使用 filefile_get_contents 函数(这会将整个文件加载到内存中,再次杀死 PHP),使用 fopen 和 fgets 读取文件一行一次.

                  Then, once the file is saved, instead of using the file or file_get_contents functions (which would load the entire file into memory, killing PHP again), use fopen and fgets to read the file one line at a time.

                  这篇关于处理一个长度为 3000 万个字符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用php的简单水平条形图 下一篇:PHP 中是否有垃圾收集?

                  相关文章

                  最新文章

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

                  <legend id='EvSbD'><style id='EvSbD'><dir id='EvSbD'><q id='EvSbD'></q></dir></style></legend>
                  <tfoot id='EvSbD'></tfoot>

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