msoa
msoa

Reputation: 1349

Loading Excel file with PHPExcel

I have following code:

public function actionSearch()
{
    $inputFileName = "C:/Apache2/htdocs/filePurchase/files/file.xlsx";
    $objReader = new PHPExcel_Reader_Excel2007();
    $objPHPExcel = $objReader->load($inputFileName);
}

When i run this action on browser, this message raised:

The connection was reset

The connection to the server was reset while the page was loading.

With following code is no problem:

$inputFileName = "C:/Apache2/htdocs/filePurchase/files/file.xlsx";
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);

What's the problem?


Edit:

var_dump($objReader):

object(PHPExcel_Reader_Excel2007)[19]
private '_referenceHelper' => 
object(PHPExcel_ReferenceHelper)[21]
protected '_readDataOnly' => boolean false
protected '_includeCharts' => boolean false
protected '_loadSheetsOnly' => null
protected '_readFilter' => 
object(PHPExcel_Reader_DefaultReadFilter)[20]
protected '_fileHandle' => null

Apache log:

[Fri Sep 13 19:46:50 2013] [notice] Parent: child process exited with status 255 -- Restarting.
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[Fri Sep 13 19:46:51 2013] [notice] Apache/2.2.23 (Win32) PHP/5.3.3 configured -- resuming normal operations
[Fri Sep 13 19:46:51 2013] [notice] Server built: Aug 24 2012 11:45:16
[Fri Sep 13 19:46:51 2013] [notice] Parent: Created child process 1184
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[Fri Sep 13 19:46:52 2013] [notice] Child 1184: Child process is running
[Fri Sep 13 19:46:52 2013] [notice] Child 1184: Acquired the start mutex.
[Fri Sep 13 19:46:52 2013] [notice] Child 1184: Starting 64 worker threads.
[Fri Sep 13 19:46:52 2013] [notice] Child 1184: Starting thread to listen on port 80.
[Fri Sep 13 19:46:52 2013] [notice] Child 1184: Starting thread to listen on port 80.
[Fri Sep 13 19:46:53 2013] [notice] Parent: child process exited with status 255 -- Restarting.
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[Fri Sep 13 19:46:54 2013] [notice] Apache/2.2.23 (Win32) PHP/5.3.3 configured -- resuming normal operations
[Fri Sep 13 19:46:54 2013] [notice] Server built: Aug 24 2012 11:45:16
[Fri Sep 13 19:46:54 2013] [notice] Parent: Created child process 4744
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[Fri Sep 13 19:46:55 2013] [notice] Child 4744: Child process is running
[Fri Sep 13 19:46:55 2013] [notice] Child 4744: Acquired the start mutex.
[Fri Sep 13 19:46:55 2013] [notice] Child 4744: Starting 64 worker threads.
[Fri Sep 13 19:46:55 2013] [notice] Child 4744: Starting thread to listen on port 80.
[Fri Sep 13 19:46:55 2013] [notice] Child 4744: Starting thread to listen on port 80.

Edit 2: In following code, var_dump($objPHPExcel); result comes and goes like a flashback. but when add a exit; after var_dump($objPHPExcel); can be seen the result:

public function actionSearch()
{
    $inputFileName = "C:/Apache2/htdocs/filePurchase/files/file.xlsx";
    $objReader = new PHPExcel_Reader_Excel2007();
    //var_dump($objReader);
    $objPHPExcel = $objReader->load($inputFileName);
    var_dump($objPHPExcel); exit;
}

var_dump($objPHPExcel); result:

object(PHPExcel)[23]
  private '_uniqueID' => string '5233fcc54c677' (length=13)
  private '_properties' => 
    object(PHPExcel_DocumentProperties)[39]
      private '_creator' => string 'TMP' (length=3)
      private '_lastModifiedBy' => string 'TMP' (length=3)
      private '_created' => int 1378454286
      private '_modified' => int 1379082907
      private '_title' => string '' (length=0)
      private '_description' => string '' (length=0)
      private '_subject' => string '' (length=0)
      private '_keywords' => string '' (length=0)
      private '_category' => string '' (length=0)
      private '_manager' => string '' (length=0)
      private '_company' => string 'Microsoft Corporation' (length=21)
      private '_customProperties' => 
        array
          empty
  private '_security' => 
    object(PHPExcel_DocumentSecurity)[40]
      private '_lockRevision' => boolean false
      private '_lockStructure' => boolean false
      private '_lockWindows' => boolean false
      private '_revisionsPassword' => string '' (length=0)
      private '_workbookPassword' => string '' (length=0)
  private '_workSheetCollection' => 
    array
      0 => 
        object(PHPExcel_Worksheet)[293]
          private '_parent' => 
            &object(PHPExcel)[23]
          private '_cellCollection' => 
            object(PHPExcel_CachedObjectStorage_Memory)[292]
              ...
          private '_rowDimensions' => 
            array
              ...
          private '_defaultRowDimension' => 
            object(PHPExcel_Worksheet_RowDimension)[302]
              ...
          private '_columnDimensions' => 
            array
              ...
          private '_defaultColumnDimension' => 
            object(PHPExcel_Worksheet_ColumnDimension)[303]
              ...
          private '_drawingCollection' => 
            object(ArrayObject)[299]
              ...
          private '_chartCollection' => 
            object(ArrayObject)[300]
              ...
          private '_title' => string 'Sheet1' (length=6)
          private '_sheetState' => string 'visible' (length=7)
          private '_pageSetup' => 
            object(PHPExcel_Worksheet_PageSetup)[295]
              ...
          private '_pageMargins' => 
            object(PHPExcel_Worksheet_PageMargins)[296]
              ...
          private '_headerFooter' => 
            object(PHPExcel_Worksheet_HeaderFooter)[297]
              ...
          private '_sheetView' => 
            object(PHPExcel_Worksheet_SheetView)[298]
              ...
          private '_protection' => 
            object(PHPExcel_Worksheet_Protection)[301]
              ...
          private '_styles' => 
            array
              ...
          private '_conditionalStylesCollection' => 
            array
              ...
          private '_cellCollectionIsSorted' => boolean false
          private '_breaks' => 
            array
              ...
          private '_mergeCells' => 
            array
              ...
          private '_protectedCells' => 
            array
              ...
          private '_autoFilter' => 
            object(PHPExcel_Worksheet_AutoFilter)[304]
              ...
          private '_freezePane' => string '' (length=0)
          private '_showGridlines' => boolean true
          private '_printGridlines' => boolean false
          private '_showRowColHeaders' => boolean true
          private '_showSummaryBelow' => boolean true
          private '_showSummaryRight' => boolean true
          private '_comments' => 
            array
              ...
          private '_activeCell' => string 'B4' (length=2)
          private '_selectedCells' => string 'B4' (length=2)
          private '_cachedHighestColumn' => string 'E' (length=1)
          private '_cachedHighestRow' => string '896' (length=3)
          private '_rightToLeft' => boolean false
          private '_hyperlinkCollection' => 
            array
              ...
          private '_dataValidationCollection' => 
            array
              ...
          private '_tabColor' => null
          private '_dirty' => boolean true
          private '_hash' => null
      1 => 
        object(PHPExcel_Worksheet)[291]
          private '_parent' => 
            &object(PHPExcel)[23]
          private '_cellCollection' => 
            object(PHPExcel_CachedObjectStorage_Memory)[3906]
              ...
          private '_rowDimensions' => 
            array
              ...
          private '_defaultRowDimension' => 
            object(PHPExcel_Worksheet_RowDimension)[3909]
              ...
          private '_columnDimensions' => 
            array
              ...
          private '_defaultColumnDimension' => 
            object(PHPExcel_Worksheet_ColumnDimension)[3910]
              ...
          private '_drawingCollection' => 
            object(ArrayObject)[1209]
              ...
          private '_chartCollection' => 
            object(ArrayObject)[3907]
              ...
          private '_title' => string 'Sheet2' (length=6)
          private '_sheetState' => string 'visible' (length=7)
          private '_pageSetup' => 
            object(PHPExcel_Worksheet_PageSetup)[1206]
              ...
          private '_pageMargins' => 
            object(PHPExcel_Worksheet_PageMargins)[1207]
              ...
          private '_headerFooter' => 
            object(PHPExcel_Worksheet_HeaderFooter)[318]
              ...
          private '_sheetView' => 
            object(PHPExcel_Worksheet_SheetView)[3904]
              ...
          private '_protection' => 
            object(PHPExcel_Worksheet_Protection)[3908]
              ...
          private '_styles' => 
            array
              ...
          private '_conditionalStylesCollection' => 
            array
              ...
          private '_cellCollectionIsSorted' => boolean false
          private '_breaks' => 
            array
              ...
          private '_mergeCells' => 
            array
              ...
          private '_protectedCells' => 
            array
              ...
          private '_autoFilter' => 
            object(PHPExcel_Worksheet_AutoFilter)[3911]
              ...
          private '_freezePane' => string '' (length=0)
          private '_showGridlines' => boolean true
          private '_printGridlines' => boolean false
          private '_showRowColHeaders' => boolean true
          private '_showSummaryBelow' => boolean true
          private '_showSummaryRight' => boolean true
          private '_comments' => 
            array
              ...
          private '_activeCell' => string 'A1' (length=2)
          private '_selectedCells' => string 'A1' (length=2)
          private '_cachedHighestColumn' => string 'A' (length=1)
          private '_cachedHighestRow' => int 1
          private '_rightToLeft' => boolean false
          private '_hyperlinkCollection' => 
            array
              ...
          private '_dataValidationCollection' => 
            array
              ...
          private '_tabColor' => null
          private '_dirty' => boolean true
          private '_hash' => null
      2 => 
        object(PHPExcel_Worksheet)[3903]
          private '_parent' => 
            &object(PHPExcel)[23]
          private '_cellCollection' => 
            object(PHPExcel_CachedObjectStorage_Memory)[3913]
              ...
          private '_rowDimensions' => 
            array
              ...
          private '_defaultRowDimension' => 
            object(PHPExcel_Worksheet_RowDimension)[3921]
              ...
          private '_columnDimensions' => 
            array
              ...
          private '_defaultColumnDimension' => 
            object(PHPExcel_Worksheet_ColumnDimension)[3922]
              ...
          private '_drawingCollection' => 
            object(ArrayObject)[3918]
              ...
          private '_chartCollection' => 
            object(ArrayObject)[3919]
              ...
          private '_title' => string 'Sheet3' (length=6)
          private '_sheetState' => string 'visible' (length=7)
          private '_pageSetup' => 
            object(PHPExcel_Worksheet_PageSetup)[3915]
              ...
          private '_pageMargins' => 
            object(PHPExcel_Worksheet_PageMargins)[3916]
              ...
          private '_headerFooter' => 
            object(PHPExcel_Worksheet_HeaderFooter)[307]
              ...
          private '_sheetView' => 
            object(PHPExcel_Worksheet_SheetView)[3917]
              ...
          private '_protection' => 
            object(PHPExcel_Worksheet_Protection)[3920]
              ...
          private '_styles' => 
            array
              ...
          private '_conditionalStylesCollection' => 
            array
              ...
          private '_cellCollectionIsSorted' => boolean false
          private '_breaks' => 
            array
              ...
          private '_mergeCells' => 
            array
              ...
          private '_protectedCells' => 
            array
              ...
          private '_autoFilter' => 
            object(PHPExcel_Worksheet_AutoFilter)[3923]
              ...
          private '_freezePane' => string '' (length=0)
          private '_showGridlines' => boolean true
          private '_printGridlines' => boolean false
          private '_showRowColHeaders' => boolean true
          private '_showSummaryBelow' => boolean true
          private '_showSummaryRight' => boolean true
          private '_comments' => 
            array
              ...
          private '_activeCell' => string 'A1' (length=2)
          private '_selectedCells' => string 'A1' (length=2)
          private '_cachedHighestColumn' => string 'A' (length=1)
          private '_cachedHighestRow' => int 1
          private '_rightToLeft' => boolean false
          private '_hyperlinkCollection' => 
            array
              ...
          private '_dataValidationCollection' => 
            array
              ...
          private '_tabColor' => null
          private '_dirty' => boolean true
          private '_hash' => null
  private '_calculationEngine' => 
    object(PHPExcel_Calculation)[24]
      private '_workbook' => 
        &object(PHPExcel)[23]
      private '_calculationCache' => 
        array
          empty
      private '_calculationCacheEnabled' => boolean true
      private 'debugLog' => null
      public 'suppressFormulaErrors' => boolean false
      public 'formulaError' => null
      private '_cyclicReferenceStack' => 
        object(PHPExcel_CalcEngine_CyclicReferenceStack)[25]
          private '_stack' => 
            array
              ...
      private '_cyclicFormulaCount' => int 0
      private '_cyclicFormulaCell' => string '' (length=0)
      public 'cyclicFormulaCount' => int 0
      private '_savedPrecision' => string '14' (length=2)
      public '_debugLog' => 
        object(PHPExcel_CalcEngine_Logger)[26]
          private '_writeDebugLog' => boolean false
          private '_echoDebugLog' => boolean false
          private '_debugLog' => 
            array
              ...
          private '_cellStack' => 
            object(PHPExcel_CalcEngine_CyclicReferenceStack)[25]
              ...
  private '_activeSheetIndex' => int 0
  private '_namedRanges' => 
    array
      empty
  private '_cellXfSupervisor' => 
    object(PHPExcel_Style)[41]
      protected '_font' => 
        object(PHPExcel_Style_Font)[42]
          protected '_name' => string 'Calibri' (length=7)
          protected '_size' => int 11
          protected '_bold' => boolean false
          protected '_italic' => boolean false
          protected '_superScript' => boolean false
          protected '_subScript' => boolean false
          protected '_underline' => string 'none' (length=4)
          protected '_strikethrough' => boolean false
          protected '_color' => 
            object(PHPExcel_Style_Color)[43]
              ...
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_fill' => 
        object(PHPExcel_Style_Fill)[44]
          protected '_fillType' => string 'none' (length=4)
          protected '_rotation' => int 0
          protected '_startColor' => 
            object(PHPExcel_Style_Color)[45]
              ...
          protected '_endColor' => 
            object(PHPExcel_Style_Color)[46]
              ...
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_borders' => 
        object(PHPExcel_Style_Borders)[47]
          protected '_left' => 
            object(PHPExcel_Style_Border)[48]
              ...
          protected '_right' => 
            object(PHPExcel_Style_Border)[50]
              ...
          protected '_top' => 
            object(PHPExcel_Style_Border)[52]
              ...
          protected '_bottom' => 
            object(PHPExcel_Style_Border)[54]
              ...
          protected '_diagonal' => 
            object(PHPExcel_Style_Border)[56]
              ...
          protected '_diagonalDirection' => int 0
          protected '_allBorders' => 
            object(PHPExcel_Style_Border)[58]
              ...
          protected '_outline' => 
            object(PHPExcel_Style_Border)[60]
              ...
          protected '_inside' => 
            object(PHPExcel_Style_Border)[62]
              ...
          protected '_vertical' => 
            object(PHPExcel_Style_Border)[64]
              ...
          protected '_horizontal' => 
            object(PHPExcel_Style_Border)[66]
              ...
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_alignment' => 
        object(PHPExcel_Style_Alignment)[68]
          protected '_horizontal' => string 'general' (length=7)
          protected '_vertical' => string 'bottom' (length=6)
          protected '_textRotation' => int 0
          protected '_wrapText' => boolean false
          protected '_shrinkToFit' => boolean false
          protected '_indent' => int 0
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_numberFormat' => 
        object(PHPExcel_Style_NumberFormat)[69]
          protected '_formatCode' => string 'General' (length=7)
          protected '_builtInFormatCode' => int 0
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_conditionalStyles' => 
        array
          empty
      protected '_protection' => 
        object(PHPExcel_Style_Protection)[70]
          protected '_locked' => string 'inherit' (length=7)
          protected '_hidden' => string 'inherit' (length=7)
          protected '_isSupervisor' => boolean true
          protected '_parent' => 
            &object(PHPExcel_Style)[41]
      protected '_index' => null
      protected '_isSupervisor' => boolean true
      protected '_parent' => 
        &object(PHPExcel)[23]
  private '_cellXfCollection' => 
    array
      0 => 
        object(PHPExcel_Style)[117]
          protected '_font' => 
            object(PHPExcel_Style_Font)[118]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[120]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[123]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[134]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[135]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[136]
              ...
          protected '_index' => int 0
          protected '_isSupervisor' => boolean false
          protected '_parent' => null
      1 => 
        object(PHPExcel_Style)[143]
          protected '_font' => 
            object(PHPExcel_Style_Font)[144]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[146]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[149]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[160]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[161]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[162]
              ...
          protected '_index' => int 1
          protected '_isSupervisor' => boolean false
          protected '_parent' => null
      2 => 
        object(PHPExcel_Style)[170]
          protected '_font' => 
            object(PHPExcel_Style_Font)[171]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[173]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[176]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[187]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[188]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[189]
              ...
          protected '_index' => int 2
          protected '_isSupervisor' => boolean false
          protected '_parent' => null
      3 => 
        object(PHPExcel_Style)[197]
          protected '_font' => 
            object(PHPExcel_Style_Font)[198]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[200]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[203]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[214]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[215]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[216]
              ...
          protected '_index' => int 3
          protected '_isSupervisor' => boolean false
          protected '_parent' => null
      4 => 
        object(PHPExcel_Style)[224]
          protected '_font' => 
            object(PHPExcel_Style_Font)[225]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[227]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[230]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[241]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[242]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[243]
              ...
          protected '_index' => int 4
          protected '_isSupervisor' => boolean false
          protected '_parent' => null
  private '_cellStyleXfCollection' => 
    array
      0 => 
        object(PHPExcel_Style)[250]
          protected '_font' => 
            object(PHPExcel_Style_Font)[251]
              ...
          protected '_fill' => 
            object(PHPExcel_Style_Fill)[253]
              ...
          protected '_borders' => 
            object(PHPExcel_Style_Borders)[256]
              ...
          protected '_alignment' => 
            object(PHPExcel_Style_Alignment)[267]
              ...
          protected '_numberFormat' => 
            object(PHPExcel_Style_NumberFormat)[268]
              ...
          protected '_conditionalStyles' => 
            array
              ...
          protected '_protection' => 
            object(PHPExcel_Style_Protection)[269]
              ...
          protected '_index' => int 0
          protected '_isSupervisor' => boolean false
          protected '_parent' => null

Upvotes: 0

Views: 2262

Answers (2)

riopiedra
riopiedra

Reputation: 148

I got the same problem but with small Excel Files. Increasing the memory limit and the execution time did not help. Finally I decided to check the Excel files and I found that the problem was in the files. The files were downloaded from an email of a third party, so I do not know how they were created. When I opened each file with MS Excel (2007), the program gave a "Protected View" warning and asked to whether “Enable Editing” or not. I enabled the file for editing and it helps in some cases, so I was able to run the PHPExcel script with them without any problem. In another cases it was necessary to resave the Excel file with MS Excel (2007) and the “Reset Connection” problem disappeared. To check if the memory was the issue, I increased the volume of the Excel file by 3 times, and the PHPExcel script still working good. I took me a week to realize where was the problem, so I hope it will help someone.

Upvotes: 1

snowman55
snowman55

Reputation: 67

I have a similar problem (code reads excel 2007 and writes to MySQL) except that if the xlsx is kept to minimal number of columns e.g. 9, and 2 rows, there's no problem. If I increase the number of columns to 10 or more, it has the connection is reset error, even though the mysql write is successful. Nothing shows up in the apache logs.

System Linux hubble.dal.design.ti.com 2.6.9-89.0.16.ELxenU #1 SMP Tue Oct 27 04:12:25 EDT 2009 x86_64

Configure Command './configure' '--prefix=/web/server/pkgs/php-5.2.3' '--with-config-file-path=/web/conf/etc' '--with-mysql=/web/server/pkgs/mysql-5.0.33' '--with-apxs2=/web/server/pkgs/apache-2.2.3/bin/apxs' '--with-libxml-dir=/web/server/pkgs/libxml2-2.6.27' '--with-db4=/web/server/pkgs/db-4.4.20' '--with-readline=/web/server/pkgs/readline-5.1' '--with-openssl=/web/server/pkgs/openssl-0.9.8g' '--with-oci8=instantclient,/web/server/pkgs/instantclient_10_2' '--with-gd=/web/server/pkgs/gd-2.0.33' '--with-xsl=/web/server/pkgs/libxslt-1.1.20' '--with-tidy=/web/server/pkgs/tidy-20070306' '--with-ldap=/web/server/pkgs/openldap-2.3.20' '--with-curl=/web/server/pkgs/curl-7.18.0' '--with-zlib-dir=/web/server/pkgs/zlib-1.2.3' '--with-mcrypt=/web/server/pkgs/libmcrypt-2.5.8' '--enable-mbstring' '--with-mysqli=/web/server/bin/mysql_config' '--with-gettext=/web/server/pkgs/gettext-0.17' '--with-mssql=/web/server/pkgs/freetds-0.82' '--with-png-dir=/web/server/pkgs/libpng-1.2.8' '--enable-zip' '--with-freetype-dir=/web/server/pkgs/freetype-2.4.0' '--enable-gd-native-ttf' '--enable-gd-imgstrttf'

Upvotes: 1

Related Questions