I'm running a PHP script on macOS (version sequoia 15.5 -- M3) using MAMP (version 6.9) with Apache and PHP 8.2. The script loads the SaxonC (version 12.7) PHP extension to perform XSLT transformations. It works perfectly when run from the command line, but crashes when accessed through the browser (i.e. under Apache).
$proc = new Saxon\SaxonProcessor();
$xsltProcessor = $proc->newXslt30Processor();
$xsltExecutable = $xsltProcessor->compileFromFile($xsltPath); // fine in terminal
objc[xxxx]: +[__NSPlaceholderSet initialize] may have been in progress in another thread when fork() was called.
objc[xxxx]: We cannot safely call it or ignore it in the fork() child process. Crashing instead.
objc[xxxx]: Set a breakpoint on objc_initializeAfterForkError to debug.
Tried so far:
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
Also set Environment Variable directly in APACHE (in MAMP - httpd.conf)
Also checked and verified that PHP is getting the env Variables.
I managed to get SaxonC 12.7 working with the following setup.
macOS 14.6.1 M3. MAMP 7.2 (not the pro version). PHP 8.4.1.
I did not set the OBJC_DISABLE_INITIALIZE_FORK_SAFETY.
However I did set DYLD_LIBRARY_PATH to the SaxonC libraries directory.
You can copy the SaxonC library to the MAMP lib directory:
cp SaxonCHE/lib/* /Applications/MAMP/Library/lib
export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib/
I built the SaxonC PHP extension by following the instructions online. Then copied the .so file produced by the build:
sudo cp modules/saxon.so /Applications/MAMP/bin/php/php8.4.1/lib/php/extensions/no-debug-non-zts-20240924/.
Next you have to create a module conf file and add it to where PHP will pick these up from. As a quick and dirty experiment I add the content extension=saxon.so
at the end of the /Applications/MAMP/bin/php/php8.4.1/conf/php.ini
file. I ran the SaxonC PHP samples from the htdocs directory and it worked. I hope that helps.
SaxonC and MAMP seems to only work with php > 8.4. The failure happens with PHP 8.2 and 8.3. More investigation is required on these version to find out what is going wrong.