duanbozhong9689 2015-12-02 14:53
浏览 33
已采纳

大csv文件上的fgets错误

I have got a couple of custom scripts running on my server to extract CSV files from a template. These files are sometimes 250,000 + lines. When i reach around this point I get this error.

Warning: Error while sending QUERY packet. PID=24022

This is linked to the packet size in the mysql query not been big enough.

I increased the mysql query size with the below, it seemed to improve it but not all the way.

    SHOW VARIABLES LIKE 'max_allowed_packet';
    set global max_allowed_packet=1073741824;
    set global net_buffer_length=1048576;

I am using a dedicated server and have lots of resource so i could increase this but am unsure how much is safe + not really sure if this is the best way to handle the situation

Below is the code that i am using (i have removed a lot of the code that is just confusing)

 $br = ']'; //this changes
 $handle = fopen($path."".$inputFileName, "r");
 while (($data = fgetcsv($handle, 0, "".$br."")) !== FALSE) 
     {
    ....... my code .... based on $data["...
  • 写回答

1条回答 默认 最新

  • douba4275 2015-12-19 11:37
    关注

    This issue was my scripts (many) where taking a long time to run. Basically i just reconnected to Mysql. All comments were here helpful

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?