PHP和Linux IPC套接字(和Dropbox)
我需要获取linux上Dropbox的状态 这是通过使用unix套接字文件作为IPC与Dropbox交互来完成的 目前,有一种方法可以做到这一点 到目前为止,我得到了以下代码:PHP和Linux IPC套接字(和Dropbox),php,sockets,unix,ipc,dropbox,Php,Sockets,Unix,Ipc,Dropbox,我需要获取linux上Dropbox的状态 这是通过使用unix套接字文件作为IPC与Dropbox交互来完成的 目前,有一种方法可以做到这一点 到目前为止,我得到了以下代码: echo 'usr='. get_current_user().'<br/>'; $address='/root/.dropbox/iface_socket'; $socket=socket_create(AF_UNIX,SOCK_STREAM,0); if(!socket_connect($socket,
echo 'usr='. get_current_user().'<br/>';
$address='/root/.dropbox/iface_socket';
$socket=socket_create(AF_UNIX,SOCK_STREAM,0);
if(!socket_connect($socket,$address))
die('socket_connect '.socket_last_error().': '.socket_strerror(socket_last_error()));
难道不是所有这些-0600
都是导致此问题的原因吗?请注意,如果Ichmod 0777 iface_socket
,则仅第一行(Access:(0600/srw------)
)发生更改;但下面的3个不是
编辑3:我在想,也许在unix/unix上移动这个主题会更好?现在还不清楚谁在这个问题上有错
编辑4:只需通过strace运行PHP脚本,如下所示:
strace php -nef /var/www/html/index.php
输出的相关行:
socket(PF_FILE, SOCK_STREAM, 0) = 3
fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_FILE, path="/root/.dropbox/iface_socket"...}, 29) = 0
fcntl(3, F_SETFL, O_RDWR) = 0
close(3) = 0
在Apache与Dropbox在同一用户下运行的罕见情况下,我只使用python命令行界面(Debian)/usr/bin/Dropbox,就像您通常从终端使用的那样
root@DevServer1:~# dropbox help
Dropbox command-line interface
commands:
Note: use dropbox help <command> to view usage for a specific command.
status get current status of the dropboxd
help provide help
puburl get public url of a file in your dropbox
stop stop dropboxd
running return whether dropbox is running
start start dropboxd
filestatus get current sync status of one or more files
ls list directory contents with current sync status
autostart automatically start dropbox at login
exclude ignores/excludes a directory from syncing
root@DevServer1:~#dropbox帮助
Dropbox命令行界面
命令:
注意:使用dropbox帮助查看特定命令的用法。
状态获取dropboxd的当前状态
帮助提供帮助
puburl获取dropbox中文件的公共url
停止dropboxd
运行返回dropbox是否正在运行
启动dropboxd
filestatus获取一个或多个文件的当前同步状态
ls列出当前同步状态的目录内容
自动启动在登录时自动启动dropbox
排除忽略/排除同步中的目录
前置脚本只能由运行dropbox的用户有效使用。其他人都应该得到“Dropbox未运行!”输出。在您的情况下,您应该能够从PHP中操作dropbox。就我个人而言,我以受限用户的身份运行Dropbox,而不是我的超级用户。使用组,您可以随意安全地链接文件夹,并强制执行文件权限
<?php
$output = shell_exec('dropbox status');
echo "<pre>$output</pre>";
在Apache与Dropbox在同一用户下运行的罕见情况下,我只会使用python命令行界面(Debian)/usr/bin/Dropbox,就像您通常在终端上使用的那样
root@DevServer1:~# dropbox help
Dropbox command-line interface
commands:
Note: use dropbox help <command> to view usage for a specific command.
status get current status of the dropboxd
help provide help
puburl get public url of a file in your dropbox
stop stop dropboxd
running return whether dropbox is running
start start dropboxd
filestatus get current sync status of one or more files
ls list directory contents with current sync status
autostart automatically start dropbox at login
exclude ignores/excludes a directory from syncing
root@DevServer1:~#dropbox帮助
Dropbox命令行界面
命令:
注意:使用dropbox帮助查看特定命令的用法。
状态获取dropboxd的当前状态
帮助提供帮助
puburl获取dropbox中文件的公共url
停止dropboxd
运行返回dropbox是否正在运行
启动dropboxd
filestatus获取一个或多个文件的当前同步状态
ls列出当前同步状态的目录内容
自动启动在登录时自动启动dropbox
排除忽略/排除同步中的目录
前置脚本只能由运行dropbox的用户有效使用。其他人都应该得到“Dropbox未运行!”输出。在您的情况下,您应该能够从PHP中操作dropbox。就我个人而言,我以受限用户的身份运行Dropbox,而不是我的超级用户。使用组,您可以随意安全地链接文件夹,并强制执行文件权限
<?php
$output = shell_exec('dropbox status');
echo "<pre>$output</pre>";
一个可行的替代方案。
请尝试以下方法:
一个可行的替代方案。
请尝试以下方法: