Segmentation fault on solaris

Topics: Developer Forum
Jan 3, 2012 at 8:37 AM

Hello,

I have a PHP app that must run on a solaris10 server, and needs to create excel files. I had some problems with Spreadsheet_Excel_Writer-0.9.2 and I'm trying to switch to PHPExcel (1.7.6). Is it a windows-only php project maybe? I can't get it to work and get segfaults already when trying to instantiate a phpexcel object with either $objPHPExcel = new PHPExcel(); or with a filename $objPHPExcel = new PHPExcel("$filename");

I have PHP 5.3.8 installed within the xampp  1.7.7  for solaris (so it does not have php_zip.dll  but I am trying to use Excel5 or CSV).
I downloaded PHPExcel-1.7.6.tgz from http://webscripts.softpedia.com/script/PHP-Clases/PHPExcel-70114.html so this seems to be written for *nix anyway.
Alternatively I downloaded the zipfile from codeplex and tried it after  mkdir and copy-ing the Classes files into my /opt/xampp/lib/php/PHPExcel-1.7.6 directory.
Nothing works.

Has someone ever managed to get it installed and running on solaris?

Is something badly wrong in my code perhaps? (below an excerpt)

require_once "PHPExcel-1.7.6/PHPExcel.php";
require_once "PHPExcel-1.7.6/PHPExcel/IOFactory.php";

$filename = $_SERVER{"DOCUMENT_ROOT"} . "/MyProject/uploadFiles/someExcelFile.xls";

$objPHPExcel = new PHPExcel();                         // this already gives the segmentation fault

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="$filename"');
header('Cache-Control: max-age=0');

$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
$worksheet->setTitle("MySheet");

$worksheet->setCellValueByColumnAndRow(0, 1, "Some DATA");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("$filename");

if ((file_exists("$filename")) && (is_readable("$filename"))) {
                @readfile($filename);
                exit(0);
} else {
                $error = "File $filename not found or not readable";
}



Thanks for help!
Roger

Jan 3, 2012 at 8:54 AM

definitely not a windows only project. I've been using it for years in a linux and osx environment. Since PHP is an interpreted language, a segfault suggests the interpreter segfaults, which seems to be as a bug in PHP itself, not in PHPExcel.

 

I personally haven't tried it on Solaris, but perhaps one of the libraries PHP uses  (like zip/xml, etc) is the culprit. If you're up for it, try running it in GDB and make a stack trace to see where it crashes!

Jan 3, 2012 at 1:09 PM
Edited Jan 3, 2012 at 2:53 PM

thanks, I will try this asap (maybe I will use truss as I am unfamiliar with gdb)
Anyway I made some progress: I managed to install xampp on windows, struggled somewhat with ENV vars and ldap and include-paths, but managed to get PHPExcel working on windows. Will keep you posted!

Edit: since the segfault does not give me a core dump, I tried the following:

gdb /opt/xampp/bin/httpd
(gdb) run -X

and before I could even start the php script with the PHPExcel code on my browser window, it already gave me the following error:

httpd: Syntax error on line 507 of /opt/xampp/etc/httpd.conf: Syntax error on line 1 of /opt/xampp/etc/extra/httpd-xampp.conf: Cannot load /opt/xampp/modules/libphp5.so into server: ld.so.1: httpd: fatal: relocation error: file /opt/xampp/modules/libphp5.so: symbol xmlTextReaderSetup: referenced symbol not found

Line 507 of httpd.conf is added by the installation of xampp and reads as follows:
Include etc/extra/httpd-xampp.conf
which has the following on line 1:
LoadModule php5_module        modules/libphp5.so
which is a 10Meg file in /opt/xampp/modules.

I'm not sure if this is the reason for the segfault, and I have no idea how to solve the relocation error...

Anyone?

Jan 4, 2012 at 8:47 AM

after some struggle to get the script authenticated with ldap, I could start it from the php command line. According to gdb man page, it does not support debugging php scripts. So I used truss and here is the last 115 lines of output. The segfault is still there but the truss doesn't make me any wiser. Is there someone who could help, please?

lstat("/opt/xampp/lib/php/PHPExcel.php", 0xFFBFCBB8) = 0
time()                                          = 1325669685
open("/opt/xampp/lib/php/PHPExcel.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 18921, PROT_READ, MAP_SHARED, 5, 0) = 0xFEDA0000
munmap(0xFEDA0000, 18921)                       = 0
close(5)                                        = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/Autoloader.php", 0xFFBFC588) = 0
lstat("/opt/xampp/lib/php/PHPExcel", 0xFFBFC450) = 0
open("/opt/xampp/lib/php/PHPExcel/Autoloader.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 1963, PROT_READ, MAP_SHARED, 5, 0) = 0xFEE90000
munmap(0xFEE90000, 1963)                        = 0
close(5)                                        = 0
access("/opt/xampp/lib/php/PHPExcel/Shared/ZipStreamWrapper.php", F_OK) = 0
access("/opt/xampp/lib/php/PHPExcel/Shared/ZipStreamWrapper.php", R_OK) = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/Shared/ZipStreamWrapper.php", 0xFFBFBFD0) = 0
lstat("/opt/xampp/lib/php/PHPExcel/Shared", 0xFFBFBE90) = 0
open("/opt/xampp/lib/php/PHPExcel/Shared/ZipStreamWrapper.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 4161, PROT_READ, MAP_SHARED, 5, 0) = 0xFEE90000
munmap(0xFEE90000, 4161)                        = 0
close(5)                                        = 0
access("/opt/xampp/lib/php/PHPExcel/Shared/String.php", F_OK) = 0
access("/opt/xampp/lib/php/PHPExcel/Shared/String.php", R_OK) = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/Shared/String.php", 0xFFBFBFE0) = 0
open("/opt/xampp/lib/php/PHPExcel/Shared/String.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 20787, PROT_READ, MAP_SHARED, 5, 0) = 0xFEDA0000
brk(0x00CD2628)                                 = 0
brk(0x00D12628)                                 = 0
munmap(0xFEDA0000, 20787)                       = 0
close(5)                                        = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/IOFactory.php", 0xFFBFCBB8) = 0
time()                                          = 1325669685
open("/opt/xampp/lib/php/PHPExcel/IOFactory.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 7120, PROT_READ, MAP_SHARED, 5, 0) = 0xFEE90000
munmap(0xFEE90000, 7120)                        = 0
close(5)                                        = 0
send(4, "07\0\0\002 S C M S S A", 11, 128)      = 11
pollsys(0xFFBFD1B8, 1, 0xFFBFD148, 0x00000000)  = 1
recv(4, "07\0\001\0\0\002\0\0\0", 98, 128)      = 11
send(4, "\b01\0\003 s e l e c t  ".., 268, 128) = 268
pollsys(0xFFBFD938, 1, 0xFFBFD8C8, 0x00000000)  = 1
recv(4, "01\0\001\t 4\0\00203 d e".., 87, 128)  = 87
pollsys(0xFFBFD8C8, 1, 0xFFBFD858, 0x00000000)  = 1
recv(4, " _ 0 606 D E S C R 206 D".., 154, 128) = 154
pollsys(0xFFBFD850, 1, 0xFFBFD7E0, 0x00000000)  = 1
recv(4, "\00603 d e f06 S C M S S".., 154, 128) = 154
pollsys(0xFFBFD8C8, 1, 0xFFBFD858, 0x00000000)  = 1
recv(4, " S S A06 D N R _ 0 606 D".., 154, 128) = 154
pollsys(0xFFBFD8C8, 1, 0xFFBFD858, 0x00000000)  = 1
recv(4, " I T I O N\f\b\003\0\0\0".., 154, 128) = 154
brk(0x00D12628)                                 = 0
brk(0x00D16628)                                 = 0
pollsys(0xFFBFD9A8, 1, 0xFFBFD938, 0x00000000)  = 1
recv(4, "  03 0 0 F05\0\0\rFE\0\0".., 154, 128) = 14
send(4, "07\0\0\002 S C M S S A", 11, 128)      = 11
pollsys(0xFFBFD1B8, 1, 0xFFBFD148, 0x00000000)  = 1
recv(4, "07\0\001\0\0\002\0\0\0", 140, 128)     = 11
send(4, "FC\0\0\003 s e l e c t  ".., 256, 128) = 256
pollsys(0xFFBFD938, 1, 0xFFBFD8C8, 0x00000000)  = 1
recv(4, "01\0\00106 B\0\00203 d e".., 129, 128) = 129
pollsys(0xFFBFD8C8, 1, 0xFFBFD858, 0x00000000)  = 1
recv(4, " E\f ?\0\n\0\0\0\n81\0\0".., 154, 128) = 154
pollsys(0xFFBFD850, 1, 0xFFBFD7E0, 0x00000000)  = 1
recv(4, "\00603 d e f06 S C M S S".., 154, 128) = 154
pollsys(0xFFBFD9A8, 1, 0xFFBFD938, 0x00000000)  = 1
recv(4, " 0 0 6 - 1 2 - 0 407 C B".., 154, 128) = 52
access("/opt/xampp/lib/php/PHPExcel/Worksheet.php", F_OK) = 0
access("/opt/xampp/lib/php/PHPExcel/Worksheet.php", R_OK) = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/Worksheet.php", 0xFFBFBFE0) = 0
open("/opt/xampp/lib/php/PHPExcel/Worksheet.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 67544, PROT_READ, MAP_SHARED, 5, 0) = 0xFCE60000
brk(0x00D16628)                                 = 0
brk(0x00D52628)                                 = 0
brk(0x00D52628)                                 = 0
brk(0x00D92628)                                 = 0
munmap(0xFCE60000, 67544)                       = 0
close(5)                                        = 0
access("/opt/xampp/lib/php/PHPExcel/IComparable.php", F_OK) = 0
access("/opt/xampp/lib/php/PHPExcel/IComparable.php", R_OK) = 0
time()                                          = 1325669685
lstat("/opt/xampp/lib/php/PHPExcel/IComparable.php", 0xFFBFBA40) = 0
open("/opt/xampp/lib/php/PHPExcel/IComparable.php", O_RDONLY) = 5
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
fstat(5, 0x00BC25E0)                            = 0
mmap(0x00000000, 1315, PROT_READ, MAP_SHARED, 5, 0) = 0xFEE90000
munmap(0xFEE90000, 1315)                        = 0
close(5)                                        = 0
    Incurred fault #6, FLTBOUNDS  %pc = 0x2F000370
      siginfo: SIGSEGV SEGV_MAPERR addr=0x2F000370
    Received signal #11, SIGSEGV [default]
      siginfo: SIGSEGV SEGV_MAPERR addr=0x2F000370
>
Jan 4, 2012 at 11:00 AM

With a lot of print statements in the constructors, I found that commenting the line $this->setTitle($pTitle);  inside Worksheet.php (about on line 331) makes the script run quite a lot further.  The next segfault is now caused by my function call  $worksheet = $objPHPExcel->getActiveSheet();    (that may be caused by the fact that I commented the setting of the worksheet title?).

Any thoughts, anyone?  It's quite important for my company to be able to solve this issue.  Thanks for helping further!

Jan 4, 2012 at 11:47 AM

verry sorry, but no clue here. However, If  your code works on a windows host, but crashes PHP on the Solaris host, maybe the PHP install on Solaris is somehow broken? Are there any other PHP projects hosted on the Solaris machine? And/or are you in the opportunity to install a different version of PHP on it?

Jan 4, 2012 at 11:50 AM

The next step: since the public function setActiveSheetIndex returns a worksheet object  ( $this->getActiveSheet();  )  there is no point in doing the following:

$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
$worksheet->setTitle("MySheet");

I replaced this by:
$worksheet = $objPHPExcel->setActiveSheetIndex(0);
$worksheet->setTitle("HAsheet");

Now (still with setTitle commented out in the constructor!) I almost get where I want. The error I'm getting now is fatal:
Fatal error: Interface 'PHPExcel_Writer_IWriter' not found in /opt/xampp/lib/php/PHPExcel/Writer/Excel5.php on line 37
Guess I have something missing in the include path?  But first I'm going to read borft's reply ;-)
Jan 4, 2012 at 12:02 PM

hello, borft...  the php (5.3.8) on the solaris host is the one which is included inside the xampp (1.7.7) package.

Something must be wrong with phpexcel autoloader on the solaris machine: the fatal error about the missing interface is gone when I explicitly include everything:

require_once "PHPExcel/Writer/IWriter.php";
require_once "PHPExcel/Writer/Excel5.php";
require_once "PHPExcel/IOFactory.php";
require_once "PHPExcel/Worksheet.php";
require_once "PHPExcel.php";

Unfortunately, I'm back to the segfault now. Maybe I will need more includes?
Thanks for coop, hope to solve this soon.
Jan 4, 2012 at 12:21 PM

more progress: adding require_once "PHPExcel/Autoloader.php" to bypass the above problem, I found out that I also need to define PHPEXCEL_ROOT in scripts that want to use PHPExcel. Now I'm getting the next fatal error:

access("/opt/xampp/lib/phpPHPExcel/Shared/ZipStreamWrapper.php", F_OK) Err#2 ENOENT

Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in /opt/xampp/lib/php/PHPExcel/Autoloader.php on line 29

although there is a file ZipStreamWrapper.php in the Shared directory. What shall I do next?

 

Coordinator
Jan 4, 2012 at 1:35 PM
Edited Jan 4, 2012 at 1:37 PM

re: I found that commenting the line $this->setTitle($pTitle); inside Worksheet.php (about on line 331) makes the script run quite a lot further.

This is known, and has been modified in the latest SVN code for precisely the reasons of performance.

re: Autoloader

It shouldn't be necessary to include every file, only PHPExcel.php itself, or a few other class files that might be directly accessed (such as Readers or the Calculation Engine) that automatically define PHPEXCEL_ROOT and include the autoloader. Note that the autoloader can clash with autoloaders used by other library scripts... latest SVN code has a modified version of the autoloader class to try and alleviate this problem.

 

I also set up the PHPExcel root directory in the include path in all my scripts before including the library, although this should not be necessary.

Jan 4, 2012 at 1:50 PM
Edited Jan 4, 2012 at 3:32 PM

hi Mark.

Thanks for info. I think maybe you slightly misunderstood my remark on the setTitle:  I didn't say 'faster', I said 'further' ;-), meaning that I get the segmentation fault when I keep the setTitle function.  Meanwhile I found that calling $cell->setValue also makes the php crash with segfault. I have the impression that somehow the $objPHPExcel is being created as read-only !  Is that possible?  if so, how do I solve that?

thanks again,
Roger

 EDIT: anything that writes to a sheet, results in segfault, though I can delete and create a sheet::

 $filename = $_SERVER{"DOCUMENT_ROOT"}."/myproject/uploadFiles/blahblah.xls";   // OK

 header('Content-Type: application/vnd.ms-excel');              // OK
 header("Content-Disposition: attachment;filename=$filename");  // OK, note double quotes!
 header('Cache-Control: max-age=0');     // does not give an error, but is it ok?

 $objPHPExcel = new PHPExcel();         // OK

 $objPHPExcel->removeSheetByIndex(0);           // OK!
 $worksheet = $objPHPExcel->createSheet();      // OK!

// $worksheet->setTitle('Mysheet');             // segfault! :-(
// $worksheet->setCellValue('A1', 'Test');      // segfault! :-(
// $worksheet->setCellValueByColumnAndRow(1, 1, "REMARK");      // segfault! :-(


Does this help?

Coordinator
Jan 4, 2012 at 4:37 PM
Edited Jan 4, 2012 at 4:39 PM

No ideas.... this sounds like PHP is failing to execute correctly, as though it's memory handling is messed up.... the truss trace is failing on memory allocation... but it's been a long time since I worked with Solaris (and never with PHP on Solaris)

Jan 5, 2012 at 8:25 AM

Mark,  I've got a phpexcel-84644.zip  (v2.1) from somewhere on the codeplex web, would it be worth a try to install that, or is it likely a waste of time?

Coordinator
Jan 5, 2012 at 10:37 AM

Possibly, it certainly includes code changes for the aforementioned setTitle() speed improvement when reading a workbook, and the changes to the autoloader; though I think your problem is more likely to be in the xampp build of PHP.

 

It might be worthwhile trying to do a build of PHP from source rather than installing from xampp

Jan 5, 2012 at 2:27 PM

OK,  I migrated to a Linux machine, fresh install  xampp-for-linux  (lampp) and extracted the "trunk/Classes" files of  PHPExcel  (v2.1)  into /opt/lampp/lib/php/PHPExcel.  Changed back my code  (because I got a fatal error  invalid index -1  in Worksheet.php ,  probably due to the removeSheetByIndex).  Now it works fine!  Unfortunately the linux machine is a production server so I will continue other development on solaris with my local sparc machine). I hope to get a working PHPExcel on solaris too, now I can wait for a few more months.  Thanks everyone.  Roger