Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP MapScript WMS failing on GetMap requests #5798

Closed
jwgda opened this issue Apr 30, 2019 · 12 comments
Closed

PHP MapScript WMS failing on GetMap requests #5798

jwgda opened this issue Apr 30, 2019 · 12 comments

Comments

@jwgda
Copy link

jwgda commented Apr 30, 2019

PHP Mapscript WMS GetMap requests are not returning any result.

WMS requests going through CGI requests with a static mapfile are successful, e.g.

http://localhost:8080/cgi-bin/mapserv.exe?map=mymap.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=TRUE&LAYERS=L_01&SRS=EPSG%3A3857&CRS=EPSG%3A3857&STYLES=&WIDTH=1920&HEIGHT=1068&BBOX=-19200000%2C-10680000%2C19200000%2C10680000

However, loading that same mapfile in PHP Mapscript with exact same parameters returns no result.

No errors are written in the MS_ERRORFILE, and owsDispatch command returns 0 (MS_SUCCESS).

Example of code that returns no result.

$oMap = new mapObj("mymap.map");
$request = new OWSRequest();
$request->setParameter('service','WMS');
$request->setParameter('SLD_VERSION','1.1.0');
msIO_installStdoutToBuffer();
$oMap->owsDispatch($request);
$contenttype = msIO_stripStdoutBufferContentType();
header('Content-type: image/png');
msIO_getStdoutBufferBytes();
msIO_resetHandlers();

@sdlime
Copy link
Member

sdlime commented Apr 30, 2019

Hi @jwgda... This should be reported via the mailing lists where many more eyes can take a look at it. Lot's of PHP/MapScript users out there but I'm not one of them. --Steve

@sdlime sdlime closed this as completed Apr 30, 2019
@jwgda
Copy link
Author

jwgda commented May 1, 2019

Seems like I'm not the only one

#5130

@sdlime
Copy link
Member

sdlime commented May 1, 2019

@jwgda, what version of everything are you running? I'll reopen this and close the old ticket... I would still take the question to the user list to see if others are experiencing the same issue. I thought this was a pretty common use case. --Steve

@jwgda
Copy link
Author

jwgda commented May 1, 2019

Thanks Steve. I'm using the MS4W 4.0 package build which contains: MapServer 7.4.0-dev, GDAL 2.4.0, Apache 2.4.38, PHP 7.2.16, MapCache 1.7dev.

I also posted to the MS4W User mailing list a couple weeks ago, but no response yet (https://lists.ms4w.com/pipermail/ms4w-users/2019-April/thread.html). If there's another list I can post to, let me know.

@sdlime
Copy link
Member

sdlime commented May 1, 2019

So this is with the Swig-based version of PHP MapScript. I'll try the same script in Perl and see what happens. You might want to try mapserver-users as well.

@jwgda
Copy link
Author

jwgda commented May 1, 2019

Correct. Thank you.

@geographika
Copy link
Member

Here is a working SWIG Python MapScript GetMap request:

extent = map.extent
print(extent)

bbox = "BBOX={},{},{},{}".format(extent.minx, extent.miny, extent.maxx, extent.maxy)
querystring = "SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&LAYERS=lakespy2&CRS=EPSG:26915&FORMAT=image/png&WIDTH=400&HEIGHT=400&{}".format(bbox)

ows_req = mapscript.OWSRequest()
ows_req.loadParamsFromURL(querystring)
success = map.OWSDispatch(ows_req)
assert success == mapscript.MS_SUCCESS

# clear the HTTP headers or we will have an invalid image
headers = mapscript.msIO_getAndStripStdoutBufferMimeHeaders()
result = mapscript.msIO_getStdoutBufferBytes()

output_file = "wms.png"
with open(output_file, "wb") as f:
    f.write(result)

@jwgda
Copy link
Author

jwgda commented May 1, 2019

This is the piece I'm missing -- could it be the reason?
headers = mapscript.msIO_getAndStripStdoutBufferMimeHeaders()

However, there is no such function (msIO_getAndStripStdoutBufferMimeHeaders) defined in the PHP SWIG Mapscript library (/ms4w/apps/phpmapscriptng-swig/include/mapscript.php) -- code attached.
mapscript.zip

@geographika
Copy link
Member

This function was made available in the 7-4 beta release as part of the Perl updates:

https://github.com/mapserver/mapserver/pull/5778/files

There is a new 7.4 release candidate out very soon, so maybe try with this?

@bragef
Copy link
Contributor

bragef commented Dec 4, 2019

I ran into the same issue porting some old PHP Mapscript code to PHP7 and SWIG Mapscript.

The problem here is apparently with msIO_getStdoutBufferBytes(), as there is no obvious way to get the content of this buffer in SWIGH PHP Mapscript.

According to the SWIG Mapscript documentation:

msIO_getStdoutBufferBytes()binary data
Fetch the current stdout buffer contents as a binary buffer. The exact form of this buffer will vary by mapscript language (eg. string in Python, byte[] array in Java and C#, unhandled in perl)

Calling $res=msIO_getStdoutBufferBytes() in PHP outputs nothing, and returns a resource handle to the buffer. (See also http://osgeo-org.1560.x6.nabble.com/PHP-Mapscript-Swig-td5404624.html).

Contrast this with the old, non-SWIG PHP Mapscript, where calling ms_iogetStdoutBufferBytes() would write content of the current buffer to stdout:

ms_iogetStdoutBufferBytes()
Writes the current buffer to stdout. The PHP header() function should be used to set the documents’s content-type prior to calling the function. Returns the number of bytes written if output is sent to stdout. See MapScript Wrappers for WxS Services for more info.

@jmckenna
Copy link
Member

jmckenna commented Dec 6, 2019

This has been just fixed by @bragef (#5943) and merged into master. Please re-try your tests with today's git-master; I confirmed the fix on Windows with PHP 7.2.

@jmckenna jmckenna closed this as completed Dec 6, 2019
@jmckenna
Copy link
Member

jmckenna commented Dec 6, 2019

MS4W will now be updated with this fix, for Windows users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants