• <small id='X1HRh'></small><noframes id='X1HRh'>

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

    1. <legend id='X1HRh'><style id='X1HRh'><dir id='X1HRh'><q id='X1HRh'></q></dir></style></legend>

        <tfoot id='X1HRh'></tfoot>
        • <bdo id='X1HRh'></bdo><ul id='X1HRh'></ul>

        批处理 php 的 fgetcsv

        时间:2023-06-22

          <tbody id='DtjYw'></tbody>

          <bdo id='DtjYw'></bdo><ul id='DtjYw'></ul>
          • <tfoot id='DtjYw'></tfoot>

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

              1. <legend id='DtjYw'><style id='DtjYw'><dir id='DtjYw'><q id='DtjYw'></q></dir></style></legend>

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

                1. 本文介绍了批处理 php 的 fgetcsv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个我无法控制的相当大的 csv 文件(至少对于网络而言).它有大约 10 万行,而且只会变得更大.

                  I have a fairly large csv file (at least for the web) that I don't have control of. It has about 100k rows in it, and will only grow larger.

                  我使用 Drupal 模块提要根据这些数据创建节点,它们的解析器以 50 行为一组对解析进行批处理.但是,他们的解析器没有正确处理引号,并且无法解析大约 60% 的 csv 文件.fgetcsv 可以工作,但据我所知不能批量处理.

                  I'm using the Drupal Module Feeds to create nodes based on this data, and their parser batches the parsing in groups of 50 lines. However, their parser doesn't handle quotation marks properly, and fails to parse about 60% of the csv file. fgetcsv works but doesn't batch things as far as I can tell.

                  在尝试使用 fgetcsv 读取整个文件时,PHP 最终会耗尽内存.因此,我希望能够将事情分解成更小的块.这可能吗?

                  While trying to read the entire file with fgetcsv, PHP eventually runs out of memory. Therefore I would like to be able to break things up into smaller chunks. Is this possible?

                  推荐答案

                  fgetcsv() 通过从给定的文件指针一次读取一行来工作.如果 PHP 内存不足,也许您正在尝试一次解析整个文件,将其全部放入一个巨大的数组中.解决方案是逐行处理,而不将其存储在大数组中.

                  fgetcsv() works by reading one line at a time from a given file pointer. If PHP is running out of memory, perhaps you are trying to parse the whole file at once, putting it all into a giant array. The solution would be to process it line by line without storing it in a big array.

                  要更直接地回答批处理问题,请从文件中读取 n 行,然后使用 ftell() 在文件中找到结束的位置.记下这一点,然后您可以在将来的某个时候通过在 fgetcsv() 之前调用 fseek() 来返回它.

                  To answer the batching question more directly, read n lines from the file, then use ftell() to find the location in the file where you ended. Make a note of this point, and then you can return to it at some point in the future by calling fseek() before fgetcsv().

                  这篇关于批处理 php 的 fgetcsv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何为创建的每个新订单、产品等订阅 DrupalCommerce 2X 事件 下一篇:如何以编程方式向 Drupal 7 中的用户配置文件添加新字段

                  相关文章

                  <legend id='EvkpD'><style id='EvkpD'><dir id='EvkpD'><q id='EvkpD'></q></dir></style></legend>

                    <tfoot id='EvkpD'></tfoot>

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

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

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