Opened 11 years ago

Closed 11 years ago

#4970 closed defect (fixed)

Calling ogr2ogr from MAMP's php fails

Reported by: dtarc Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SRS Version: unspecified
Severity: normal Keywords: vsistdout ogr2ogr
Cc:

Description

Hi,

I think the issue I am having is with my php configuration as opposed to something ogr2ogr is doing but this seems like the most likely place to get help.

We've been using ogr2ogr to do geodata conversions in a drupal project for over a year now. We have it running on various servers and it was working fine on my dev environment. Recently I rebuilt my dev environment, switching from Mac OS X Lion to Mac OS X Mountain Lion and starting from scratch, and I can no longer get valid info back when calling ogr2ogr from PHP.

I am using MAMP and PHP 5.3.14. Also using the bare bones drupal module (http://drupal.org/project/ogr2ogr). I was using GDAL 1.9.2, but when it wasn't working I downgraded to 1.8.1. I have installed it using Homebrew.

GDAL seems to be installed correctly as I can call ogr2ogr commands from the command line and I get valid data returned. When I call the same command from PHP, I don't get anything back.

Here is the command I am trying to run:

/usr/bin/ogr2ogr -f CSV /vsistdout/ "/path/to/SHAPEFILE.shp" -lco GEOMETRY=AS_WKT -t_srs EPSG:4326

If I run it from the command line, I get valid WKT results returned in CSV format.

Running from PHP, I'm executing the following code:

<code>

Build $command

...

if (($handle = popen($command, "r")) !== FALSE) {

while (($data = fgetcsv($handle)) !== FALSE) {

Process incoming data

}

}

</code>

The popen command seemed to return a valid file handle and gets evaluated as TRUE. Hoever the fgetcsv() call always returns FALSE. I have subbed in fgets() and that will also return FALSE. Again, this is an ogr2ogr command that returns data when called from the shell.

I got a tip to make sure that the php environment variable auto_detect_line_endings was set to TRUE but that did not help.

Does anyone have any suggestions? Thanks in advance.

Change History (1)

comment:1 by dtarc, 11 years ago

Resolution: fixed
Status: newclosed
Summary: Can't read /vsistdout/ via php's popen() on Mac OS X Mountain LionCalling ogr2ogr from MAMP's php fails

I have resolved my issue. It turns out the conflict was with MAMP. So currently ogr2ogr called from MAMP php will not work without making a change to MAMP.

Here's the error I had in MAMP's apache error log:

dyld: Library not loaded: /usr/local/lib/libpng15.15.dylib
  Referenced from: /usr/bin/ogr2ogr
  Reason: Incompatible library version: ogr2ogr requires version 29.0.0 or later, but libpng15.15.dylib provides version 23.0.0

A co-worker got this error:

dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib
  Referenced from: /usr/bin/ogr2ogr
  Reason: Incompatible library version: ogr2ogr requires version 13.0.0 or later, but libjpeg.8.dylib provides version 12.0.0

A similar conflict with MAMP that's well documented is the MAMP-ImageMagick conflict - http://www.maratz.com/blog/archives/2010/05/11/imagemagick-with-mamp/

So the fix is to disable MAMP's DYLD_LIBRARY_PATH variable.

Edit MAMP's environment variable settings file:

sudo vi /Applications/MAMP/Library/bin/envvars

Comment out the two lines that set and export the path, which should then look like:

#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
Note: See TracTickets for help on using tickets.