I have a macOS server with a little site which converts text snippets to audio using say
command.
With upgrade to Sierra, everything went smooth except one thing: the say
command doesn't work any more when wrapped in exec()
in my PHP script.
The page just times out. No error is caught either.
<?php
try {
exec('/usr/bin/say "hello"');
}
catch (Exception $e) { echo $e->getMessage(); }
?>
Typically I would save the audio snippets with say -o filename
but I tried all the variants and also other shell commands which worked fine including creating files in my output folder.
Interesting is that if I run it from a command line, it works - either says it loud or creates an output file.
macOS Sierra has PHP 5.6.24 so I don't think safe_mode applies, righht?
I would like to emphasise that the change in either PHP or say command was quite recent, with the new OS. Yes I did look into and tried different output and stderr redirection but the script just hangs.
Seeing the say
command in Activity Viewer (GUI for top
equivalent), I tried to sample it, not sure if it helps:
2695 Thread_1742595 DispatchQueue_1: com.apple.main-thread (serial)
+ 2695 start (in libdyld.dylib) + 1 [0x7fffb0f58255]
+ 2695 ??? (in say) load address 0x10907d000 + 0x1fac [0x10907efac]
+ 2695 NewSpeechChannel (in SpeechSynthesis) + 52 [0x7fff9acd3f19]
+ 2695 SpeechChannelHandle::SpeechChannelHandle() (in SpeechSynthesis) + 265 [0x7fff9acd797f]
+ 2695 dispatch_once_f (in libdispatch.dylib) + 38 [0x7fffb0f220e5]
+ 2695 _dispatch_client_callout (in libdispatch.dylib) + 8 [0x7fffb0f22128]
+ 2695 ___ZN13SpeechGlobals8InstanceEv_block_invoke (in SpeechSynthesis) + 28 [0x7fff9acd54da]
+ 2695 SpeechGlobals::SpeechGlobals() (in SpeechSynthesis) + 471 [0x7fff9acd56db]
+ 2695 xpc_connection_send_message_with_reply_sync (in libxpc.dylib) + 154 [0x7fffb11b65a8]
+ 2695 dispatch_mach_send_with_result_and_wait_for_reply (in libdispatch.dylib) + 45 [0x7fffb0f3cf39]
+ 2695 _dispatch_mach_send_and_wait_for_reply (in libdispatch.dylib) + 591 [0x7fffb0f3cad4]
+ 2695 mach_msg (in libsystem_kernel.dylib) + 55 [0x7fffb107e867]
+ 2695 mach_msg_trap (in libsystem_kernel.dylib) + 10 [0x7fffb107f41a]
2695 Thread_1742600
2695 start_wqthread (in libsystem_pthread.dylib) + 13 [0x7fffb116f211]
2695 _pthread_wqthread (in libsystem_pthread.dylib) + 1426 [0x7fffb116f7b5]
2695 __workq_kernreturn (in libsystem_kernel.dylib) + 10 [0x7fffb10874e6]
And from open files and ports, I could see that I set both stdout
and stderr
to /private/var/log/apache2/error_log
yet nothing shows there at all.
Also, tried to capture outputs with more elaborate run, but no joy, just timeout (the script folder is also writable):
<?php
try {
$pipes = array();
proc_close(proc_open("say hi", array(0 => array("pipe", "r"), 1 => array("pipe", "r"), 2 => array("pipe", "r")), $pipes, dirname(__FILE__), null));
} catch (Exception $e) { error_log($e->getMessage()); }
?>
UPDATE: High Sierra is the same.
FINAL UPDATE: after installing Mojave, which removes most of the Server.app features, I added MAMP to handle this task. Hear it for yourselves if you wish - it's at macspeaks.com.
THE STORY CONTINUES: somehow during the install of Catalina, or was it MAMP update? (now on 5.5), I killed it again. Sigh...