php exec 文件从终端运行,而不是从浏览器运行
php exec file runs from terminal, not from browser
我有一个程序可以启动我的屏幕保护程序:
<?php
$cmd='automator /Users/myusername/Library/Services/Start_Screensaver.workflow';
shell_exec($cmd);
?>
当我 运行 它与
php index.php
它工作正常,但是当我尝试从浏览器 运行 它时,我总是在 apache error_log 文件中收到以下错误:
The workflow file does not exist.
我觉得这很奇怪,因为我确实有从根文件夹开始的正确路径。任何帮助,将不胜感激。谢谢!
此外,虽然我很确定 apache 在我的 mac 上设置正确,但我只能通过我的 mac 的 ip 地址在我的 mac 本身上访问网页.因此,例如,当我在 phone 上访问 Mac 的 IP 时,它无法加载页面,但是当我访问 Raspberry Pi 的 IP 地址时(这也是 运行s apache) 它工作正常。
编辑:需要明确的是,这样做的目的不是在我的 Mac 上启动屏幕保护程序,而是在 Tasker
中从我的 phone 远程启动它
编辑:我将 automator 工作流文件放在同一目录中并执行
sudo chmod 777 start_screensaver.workflow
现在我收到以下错误:
2015-12-24 19:12:26.376 automator[2313:462937] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:26.377 automator[2313:462937] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:26.677 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.678 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.679 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.680 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:27.757 Automator Runner[2314:462973] Script Monitor is missing or damaged: Error Domain=NSCocoaErrorDomain Code=256 "The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)." UserInfo={NSURL=file:///System/Library/CoreServices/ScriptMonitor.app/, NSLocalizedDescription=The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)., NSUnderlyingError=0x7f80f3411190 {Error Domain=NSOSStatusErrorDomain Code=-10810 "kLSUnknownErr: Unexpected internal error"}}
2015-12-24 19:12:27.758 Automator Runner[2314:462973] Script Monitor is missing or damaged
2015-12-24 19:12:27.843 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.846 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.872 Automator Runner[2314:462980] warning: failed to get scripting definition from /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app; it may not be scriptable.
2015-12-24 19:12:27.966 Automator Runner[2314:462980] Scripting Bridge could not launch application /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app.
2015-12-24 19:12:27.997 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-user-standardLocations.plist: The folder “com.apple.automator.actionCache-user-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:30.830 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-system-standardLocations.plist: The folder “com.apple.automator.actionCache-system-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:31.148 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist: The folder “com.apple.automator.actionCache-bundleLocations.plist” doesn’t exist.
您的 Apache 用户似乎无权访问该目录。当你从 cli 运行 php 脚本时,你 运行 它们是 myusername
,但是,一旦你从浏览器打开它,它是一个 different user (_www
).
因此,您需要确保 _www
用户可以访问该文件。将该文件的权限设置为 777
可能会做到这一点。
P.S.: 顺便说一句,@Mike 是绝对正确的,您应该重新考虑您使用脚本的方式。
UPD
屏幕保护程序启动,太棒了。因此,问题全在于权限。因此,您可以尝试 运行 使用 php 内置服务器
php -S localhost:8000 index.php
或者配置apache和change the apache user。
或者,您可以将所有与屏幕保护程序相关的内容移动到一个可公开访问的目录,但是,同样,这可能会导致一些安全漏洞。
我有一个程序可以启动我的屏幕保护程序:
<?php
$cmd='automator /Users/myusername/Library/Services/Start_Screensaver.workflow';
shell_exec($cmd);
?>
当我 运行 它与
php index.php
它工作正常,但是当我尝试从浏览器 运行 它时,我总是在 apache error_log 文件中收到以下错误:
The workflow file does not exist.
我觉得这很奇怪,因为我确实有从根文件夹开始的正确路径。任何帮助,将不胜感激。谢谢!
此外,虽然我很确定 apache 在我的 mac 上设置正确,但我只能通过我的 mac 的 ip 地址在我的 mac 本身上访问网页.因此,例如,当我在 phone 上访问 Mac 的 IP 时,它无法加载页面,但是当我访问 Raspberry Pi 的 IP 地址时(这也是 运行s apache) 它工作正常。
编辑:需要明确的是,这样做的目的不是在我的 Mac 上启动屏幕保护程序,而是在 Tasker
中从我的 phone 远程启动它编辑:我将 automator 工作流文件放在同一目录中并执行
sudo chmod 777 start_screensaver.workflow
现在我收到以下错误:
2015-12-24 19:12:26.376 automator[2313:462937] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:26.377 automator[2313:462937] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:26.677 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.678 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.679 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:26.680 automator[2313:462937] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Create Table from Data in Workbook.action: No bundleIdentifier.
2015-12-24 19:12:27.692 Automator Runner[2314:462973] Not loading action at /Library/Automator/Save Outlook Messages as Files.action: No bundleIdentifier.
2015-12-24 19:12:27.757 Automator Runner[2314:462973] Script Monitor is missing or damaged: Error Domain=NSCocoaErrorDomain Code=256 "The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)." UserInfo={NSURL=file:///System/Library/CoreServices/ScriptMonitor.app/, NSLocalizedDescription=The application “ScriptMonitor” could not be launched because a miscellaneous error occurred (OSStatus -10810)., NSUnderlyingError=0x7f80f3411190 {Error Domain=NSOSStatusErrorDomain Code=-10810 "kLSUnknownErr: Unexpected internal error"}}
2015-12-24 19:12:27.758 Automator Runner[2314:462973] Script Monitor is missing or damaged
2015-12-24 19:12:27.843 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.844 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.846 Automator Runner[2314:462973] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-12-24 19:12:27.872 Automator Runner[2314:462980] warning: failed to get scripting definition from /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app; it may not be scriptable.
2015-12-24 19:12:27.966 Automator Runner[2314:462980] Scripting Bridge could not launch application /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app.
2015-12-24 19:12:27.997 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-user-standardLocations.plist: The folder “com.apple.automator.actionCache-user-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:30.830 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-system-standardLocations.plist: The folder “com.apple.automator.actionCache-system-standardLocations.plist” doesn’t exist.
2015-12-24 19:12:31.148 Automator Runner[2314:462973] Error writing cache to /Library/WebServer/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist: The folder “com.apple.automator.actionCache-bundleLocations.plist” doesn’t exist.
您的 Apache 用户似乎无权访问该目录。当你从 cli 运行 php 脚本时,你 运行 它们是 myusername
,但是,一旦你从浏览器打开它,它是一个 different user (_www
).
因此,您需要确保 _www
用户可以访问该文件。将该文件的权限设置为 777
可能会做到这一点。
P.S.: 顺便说一句,@Mike 是绝对正确的,您应该重新考虑您使用脚本的方式。
UPD
屏幕保护程序启动,太棒了。因此,问题全在于权限。因此,您可以尝试 运行 使用 php 内置服务器
php -S localhost:8000 index.php
或者配置apache和change the apache user。
或者,您可以将所有与屏幕保护程序相关的内容移动到一个可公开访问的目录,但是,同样,这可能会导致一些安全漏洞。