Changing macOS Sierra prevents "say" to be exec'd in a PHP script

I have a MacOS server with a small site that converts text fragments to audio using the command say.

Everything went smoothly with the upgrade to Sierra, except for one thing: the command sayno longer works when it is included exec()in my PHP script.

The page just stops working. No error detected.

<?php
    try {
        exec('/usr/bin/say "hello"');
    }
    catch (Exception $e) { echo $e->getMessage(); }
?>

I usually saved audio fragments say -o filenamewith, say -o filenamebut I tried all the options, as well as other shell commands that worked fine, including creating files in my output folder.

Interestingly, if I run it from the command line, it works - it either speaks loudly or creates an output file.

macOS Sierra PHP 5.6.24, , safe_mode , ?

, PHP say , . , stderr, .

say Activity Viewer (GUI top ), , , :

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]

: Activity Viewer> Statistics

, stdout stderr /private/var/log/apache2/error_log .

, , , ( ):

<?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()); }
?>

: - .

: Mojave, Server.app, MAMP . , - macspeaks.com.

+4
2

.

, , , , , BIG MESS, php script apache. , , , , . , TTY. , sudo -i MANY MANY attmepts php, , , , , SSH " , . , , WAY overkill, , -, php ( -).

, , , , :

php script /tmp , :

exec "sudo -u <username> /usr/bin/say -o /tmp/outputfile.aiff --voice=Ava \"<What to Say>\"";

, , , (, , ) apache/php, - script ssh . , :

exec "sudo -u <username> -i ~<username>/expectscript";

script :

#!/usr/bin/expect -f

spawn /usr/bin/ssh localhost
expect "Password"
send "<PASSWORD>\r"
expect "<username>"
send "/usr/bin/afplay /tmp/outputfile.aiff\r"
expect "<username>"
send "/usr/bin/touch /tmp/touchthis\r"
expect "<username>"
send "exit\r"

, <username> ( < > ) <PASSWORD> . , script, bash , , script, . - , script , , .

, , , . , , Automator PHP ( ). , , . , , ( php ), Apache/PHP.

0

say Jenkins. Jenkins macOS Sierra.

:

  • jenkins ssh ssh-keygen.
  • ~/.ssh/id_rsa.pub .ssh/authorized-keys, .

    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized-keys
    
  • Jenkins, say :

    ssh localhost say -v Alex "Test"
    

, Apache/PHP, :

<?php
    try {
        exec('/usr/bin/ssh localhost /usr/bin/say "hello"');
    }
    catch (Exception $e) { echo $e->getMessage(); }
?>
0

Source: https://habr.com/ru/post/1658772/


All Articles