用PHP重新加载ROOT服务(例如SPHINX Search)


Reload ROOT service with PHP (f.e. SPHINX Search)

我需要通过PHP重新加载SPHINX SEARCH。在终端我这样做:

sudo indexer --all --rotate

它工作得很好,但是现在我需要通过php来做。

初版shell_exec('sudo indexer --all --rotate');

它不起作用。如果我尝试使用www-data user,我会得到:

Sphinx 2.2.9-id64-release (rel22-r5006)版权所有(c) 2001-2015Copyright (c) 2008-2015, Sphinx Technologies Inc(http://sphinxsearch.com)

使用配置文件'/etc/sphinxsearch/sphinx.conf'…跳过非普通索引'rt'…索引"test1"…警告:属性没有找到'id' -忽略收集的49433个文档,45.1 MB排序4.8总共49433个文档,45067658个字节,总共5.540秒。8133618字节/秒,8921.45文档/秒总共49607个读取,0.042秒,1.9Kb/call avg, 0.0 msec/call avg总共424次写,0.106秒,373.8警告:拒绝访问PID 16315。

警告:拒绝访问PID 16315。!!!

如果我试图停止并启动SPHINX与www-data,我得到:

start:拒绝发送消息,1个匹配规则;type = " method_call ",Sender =":1.4502" (uid=33 pid=16887 comm="start sphinxsearch ")界面= " com.ubuntu.Upstart0_6。Job" member="Start"错误name="(unset)" requestd_reply ="0" destination="com.ubuntu.Upstart"(uid=0 pid=1 comm="/sbin/init ")

我正在玩sh脚本shmod和chown,我什么也没得到

您也应该在www-data用户下开始搜索。避免使用sudo。(虽然可以允许sudo via, visudo)

所以停止搜索。将所有索引、日志和pid等更改为www-data所有,然后

#stop current instance
searchd --stop
#change the owner of indexes and logs
chown www-data:www-data /path/to/index/folder/ -r 
chown www-data:www-data /var/log/query.log 
chown www-data:www-data /var/log/search.log 
#start searchd up again
sudo -u www-data searchd

然后apache中的php(运行为www-data)可以根据需要调用indexer。

如果你想使用upstart等,将需要修改它的配置文件,以一个特定的用户运行searchd(不能仅仅通过以一个特定的用户运行来调用service start/stop)。