如何在PHP中读取大型CSV文件?

时间:2019-11-27 07:15:41

标签: php

我正在尝试使用PHP读取具有800000行的CSV文件,但出现此错误:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { FormBuilder, FormGroup } from "@angular/forms";
import { Tutorial } from './../models/tutorial.model';
import { AppState } from './../app.state';
import * as TutorialActions from './../actions/tutorial.actions';
import { getCurrentCustomerId } from '../reducers/tutorial.reducer';

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.css']
})
export class EditComponent implements OnInit {
  //tutorialForm: FormGroup;
  tutorials:any;

  constructor(private fb: FormBuilder, private store: Store<AppState>) {}

  ngOnInit() {

    const customer$: Observable<any> = this.store.select(
      getCurrentCustomerId
    );

    console.log(customer$);

我该如何解决?

2 个答案:

答案 0 :(得分:1)

您可以按块阅读它。

<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}

答案 1 :(得分:-1)

您可以添加此行以为进程设置更多的内存:

 ini_set('memory_limit', '1024M'); // or you could use 1G