PHP/Mapscript regex problem -- Any volunteers?

Daniel Morissette dmorissette at DMSOLUTIONS.CA
Fri May 13 08:22:59 EDT 2005


Bill Binko wrote:
>
> However, I have had one devil of a time getting it to build.  Now it
> builds, and crashes on startup.
>
> I think I have an idea what one of the problems are: msEvalRegex() is
> sending a stack address to regfree(), which then corrupts the stack.  The
> non-php regex library is probably more forgiving.
>

It's not that the non-php regex library is more forgiving. The key is
that you need to make sure that both your PHP and the
MapServer/MapScript code are compiled with the same regex. The reason is
that the PHP regex and the system regex use the same function names and
regex_t data structure, but they are defined differently and with a
different size. When you compile PHP and MapScript with different regex
libs, then at runtime you end up with duplicate sets of regex symbol
names, and depending on where you are in the code, the wrong symbols
could sometimes be used randomly and lead to the crashes you've experienced.

> I would be happy to work with anyone else in solving this problem.
> Ideally, the build could be improved to not require the PHP sources as
> well (as long as the .h and .so files were there).  I have not
> investigated into doing that.
>

Well, I'd like an easy fix for this but I don't think there's one.

The reason why we require the source if you are using the PHP built-in
regex is that at the moment, an installed PHP package exposes the
regex/*.h files, but doesn't expose the regex/*.o files We could compile
php_mapscript.so from the .h files and the regex symbols would be
resolved at runtime because they are part of the php executable, but
that wouldn't work for the mapserv and other command-line executables,
they'll require the regex/*.o files to link with. The only alternative
then would be to do separate builds everytime for php_mapscript.so and
for the mapserver core binaries, quite a clunky solution.

The best solution in my opinion is that PHP should be designed to use
the system regex... that's what system libraries are for after all: all
packages on a system that require a given library should use the system
copy so that they can easily interact. Well, someone in the PHP team
seems to have a preference for built-in libraries, so much that they
made it impossible to use the system regex in some circumstances, and
our two worst nightmares with PHP are the built-in regex and the
built-in GD that both cause the same similar build and runtime problems.

Well, one possible solution could be for us to also package our own
built-in regex after renaming the regex_t data structure and all the
functions, but I think that would be a move backwards.

So if you or someone else can get a hold of someone in the PHP dev't
team and get an explanation of why they force the use of the built-in
regex and what they propose as a solution to this mess, then we may be
on the way to find a solution.


Note that the above is based on information I had the last time I looked
into this, maybe a year ago. It's possible that something changed in PHP
since then (maybe in PHP 5)? to make it easier to integrate PHP with
large packages such as MapServer, if that's the case then I'd like to be
pointed in the right direction.

Daniel

P.S. An alternative to doing your own builds would be to use the
precompiled FGS Linux packages: http://maptools.org/fgs/ ... you'd be
running with PHP MapScript in a few minutes.
--
------------------------------------------------------------
  Daniel Morissette               dmorissette at dmsolutions.ca
  DM Solutions Group              http://www.dmsolutions.ca/
------------------------------------------------------------



More information about the mapserver-dev mailing list