PHPExcel在执行的中间停止

PHPExcel在执行的中间停止,php,cakephp,Php,Cakephp,我用它来读取excel并将其存储在数据库中。 当记录数少于500时,它工作正常。 如果EXCEL中的记录高达2000,则在加载400到500行后,在没有任何错误的情况下停止在中间。 注意:我正在使用sqlite来减少内存使用,但我仍然面临这个问题 这是我的密码。请建议使其可行 ini_set('max_execution_time', 0); set_time_limit(0) ; //Set memory limit to maximum... ini_

我用它来读取excel并将其存储在数据库中。 当记录数少于500时,它工作正常。 如果EXCEL中的记录高达2000,则在加载400到500行后,在没有任何错误的情况下停止在中间。 注意:我正在使用sqlite来减少内存使用,但我仍然面临这个问题

这是我的密码。请建议使其可行

    ini_set('max_execution_time', 0);
    set_time_limit(0) ;
    //Set memory limit to maximum...

       ini_set('memory_limit', '-1');
    error_reporting(E_ALL);

        set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');



/** PHPExcel_IOFactory */
    include $unsecured_param['home_dir'].'APIs/PHPExcelReader/Classes/PHPExcel/IOFactory.php';
    //echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
    //if you only want to read certain cells within worksheets, you can add a filter:
                $inputFileType = 'Excel2007';

    /**  Define a Read Filter class implementing PHPExcel_Reader_IReadFilter  */
        class chunkReadFilter implements PHPExcel_Reader_IReadFilter
        {
        private $_startRow = 0;
        private $_endRow = 0;
        /**  Set the list of rows that we want to read  */
        public function setRows($startRow, $chunkSize) {
        $this->_startRow    = $startRow;
        $this->_endRow      = $startRow + $chunkSize;
              }
                    public function readCell($column, $row, $worksheetName = '') {
                        //  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
                        if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
                            return true;
                        }
                        return false;
                    }
                }

             echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
            /**  Create a new Reader of the type defined in $inputFileType  **/
            $objReader = PHPExcel_IOFactory::createReader($inputFileType);


            echo '<hr />';


            /**  Define how many rows we want to read for each "chunk"  **/
            $chunkSize = 20;
            /**  Create a new Instance of our Read Filter  **/
            $chunkFilter = new chunkReadFilter();

            /**  Tell the Reader that we want to use the Read Filter that we've Instantiated  **/
            $objReader->setReadFilter($chunkFilter);

            /**  Loop to read our worksheet in "chunk size" blocks  **/
            for ($startRow = 1; $startRow <= 2000; $startRow += $chunkSize) {
                echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
                /**  Tell the Read Filter, the limits on which rows we want to read this iteration  **/
                $chunkFilter->setRows($startRow,$chunkSize);
                $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
                $cacheSettings = array( 
                    'cacheTime' => 600
                );
                PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
                /**  Load only the rows that match our filter from $inputFileName to a PHPExcel Object  **/
                $objPHPExcel = $objReader->load($inputFileName);
                //  Do some processing here
                $range_xl="A".($startRow).":X".($startRow + $chunkSize);
                echo "$range_xl.<br>";
                $sheetData = $objPHPExcel->getActiveSheet()->rangeToArray($range_xl,null,true,true,true);
                //var_dump($sheetData);
                unset($objPHPExcel);
                //store data into array..
                $i=0;$h=1;
                foreach($sheetData as $rec)
                {
                    foreach($rec as $part)
                    {
                        $items[$i]=$part; //echo "items $i]=" ; echo $items[$i];echo "<br>";
                        $i=$i+1;            
                    }
                    $i=0;//1 row completed
                    $h=$h+1;//echo $items[0]."<br>";
    //echo "<br>---------------------<br>";             
    //start loading a row into database..
    if($h>4) {
    //store excel values
    $sno=trim($items[0]);echo $sno."<br>";
    $cat=trim($items[1]);
    $id_xl=trim($items[2]);
    $name=trim($items[3]);
    .... 

我怀疑是内存问题。即使您已经设置了内存限制,但根据经验,我知道您的服务器上通常有一个硬限制,使用ini设置时无法超过。您的Excel文件大小是多少?请确保您使用的转换器或插件已更新。@cale\u b:这就是为什么我尝试将结果分割为块并执行此操作的原因。有没有更好的方法来处理这个问题?@IsaacRajaei:我是从phpexcelGit下载的最新版本