php exec文件从终端运行,而不是从浏览器运行
I have a program that should start my screensaver:
我有一个程序应该启动我的屏幕保护程序:
<?php
$cmd='automator /Users/myusername/Library/Services/Start_Screensaver.workflow';
shell_exec($cmd);
?>
When I run it with
当我运行它时
php index.php
it works fine but when I try to run it from a browser I always get the following error in the apache error_log file:
它工作正常,但当我尝试从浏览器运行它时,我总是在apache error_log文件中收到以下错误:
The workflow file does not exist.
Which I find very weird since I do have the correct path starting from the root folder. Any help would be appreciated. Thank you!
我觉得非常奇怪,因为我从根文件夹开始有正确的路径。任何帮助,将不胜感激。谢谢!
Also, although I'm pretty sure apache is setup correctly on my mac I can only acces the web pages via the ip adres of my mac on my mac itself. So when I go to my Mac's IP on my phone for example it can't load the page, but when I go to my Raspberry Pi's IP address (which also runs apache) it works fine.
此外,虽然我非常确定在我的Mac上正确设置了apache,但我只能通过我的Mac上的mac adres来访问网页。因此,当我在手机上使用Mac的IP时,例如它无法加载页面,但是当我转到我的Raspberry Pi的IP地址(也运行apache)时,它运行正常。
Edit: To be clear, the point of this is not to start the screensaver on my Mac but to start it remotely from my phone inside Tasker
编辑:要清楚,重点是不要在我的Mac上启动屏幕保护程序,而是从我的手机里面的Tasker远程启动它
Edit: I put the automator workflow file in the same directory and did
编辑:我将automator工作流文件放在同一目录中并做了
sudo chmod 777 start_screensaver.workflow
and now I'm getting the following errors:
现在我收到以下错误:
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.
1 个解决方案
#1
1
It looks like your Apache user does not have access to that directory. When you run php scripts from cli, you run them as myusername
, but, once you open it from browser, it's a different user (_www
).
看起来您的Apache用户无权访问该目录。当你从cli运行php脚本时,你将它们作为myusername运行,但是,一旦你从浏览器打开它,它就是一个不同的用户(_www)。
So, you need to make sure that the file is accessible by the _www
user. Setting permissions to 777
for that file would probably do the thing.
因此,您需要确保_www用户可以访问该文件。为该文件设置777的权限可能会做到这一点。
P.S.: btw @Mike is absolutely right that you should rethink the way you're using your script.
P.S。:btw @Mike是绝对正确的,您应该重新考虑使用脚本的方式。
UPD
The screensaver launches, that's cool. So, the issue is all about permissions. So, you can either try to run it with php built-in server
屏幕保护程序启动,这很酷。所以,问题在于权限。所以,您可以尝试使用php内置服务器运行它
php -S localhost:8000 index.php
Or configure apache and change the apache user.
或者配置apache并更改apache用户。
Alternatively, you can move all your screensaver-related stuff yo a publicly accessible dir, but, again, this may potentially cause some security flaws.
或者,您可以将所有与屏幕保护程序相关的内容移动到可公开访问的目录中,但同样,这可能会导致一些安全漏洞。
更多相关文章
- log4php将不同级别的日志打印到不同的日志文件中
- PHP - 在外部服务器上读取文件?
- 仅在LARAVEL或AJAX中提交表单时,无需用户身份验证即可将文件上载
- PHP ZipArchive 实现压缩解压Zip文件
- 纯php文件不加结束标记的好处
- 大文件从指定行开始读取
- 找不到go-pear。bat文件PHP 5.5 Windows 7。
- 将csv文件保存到现有文件,但在新工作表和重命名工作表中
- php.ini与php-fpm.conf配置文件的区别