I have a PHP script that reads a file via fgetcsv
through PHP's zip://
wrapper. This works fine locally and when run on production via a cron job. It fails with a Segmentation fault when invoked on production via CLI though, apparently at the end of reading the file when fgetcsv
returns false
.
The relevant parts of the script:
#!/usr/local/bin/php5
<?php
...
$i = 0;
while (($row = fgetcsv($file)) !== false) {
// processing ...
if (++$i % 50000 == 0) {
echo '.';
}
}
printf("\nFinished reading %s records.\n\n", number_format($i));
fclose($file);
And its output:
-bash-3.00$ ./script.php
Reading file.zip................Segmentation fault
It appears to segfault before the printf
but after having read all the records, so I suspect it fails when it reaches the end of the file.
-bash-3.00$ /usr/local/bin/php5 -v
PHP 5.2.8 (cli) (built: Apr 14 2010 16:08:06)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with the ionCube PHP Loader v3.1.31, Copyright (c) 2002-2007, by ionCube Ltd.
What could be the cause for this and is there a way to fix it?