Home > Backend Development > PHP Tutorial > How to use php to create a socket without permission in BS mode_PHP tutorial

How to use php to create a socket without permission in BS mode_PHP tutorial

WBOY
Release: 2016-07-13 17:53:14
Original
921 people have browsed it

Recently, I wrote a monitoring interface for the southern base platform, using the BS architecture, which has a function to monitor whether the virtual machine is down.
The process is: the monitoring machine issues an access request --> interface analysis request --> starts the socket to detect whether the target virtual machine is down.
Because it is detected through the ICMP protocol, the socket type SOCK_RAW is used.
The server uses apache + php + mysql, and a program error was found, prompting that there is no permission to create a socket. Later, I checked the resources and learned that this type of socket requires root permissions or running php in cgi mode combined with setuid() to create a socket.
Solution: Use nginx+php-cgi+mysql instead.
When compiling php, the following modifications must be made to start the service as the root user.

1. Find the source code of php $src_path/sapi/cgi/fpm/fpm_unix.c (the versions are different, it is best to use find $src_path -name fpm_unix.c)

2. Add a macro definition at the top of the file: #define I_REALLY_WANT_ROOT_PHP

3. Reconfigure make make install

4.php-fpm.conf Modify user and group to root


Author: penguim

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478048.htmlTechArticleRecently wrote a monitoring interface for the southern base platform, using BS architecture, including one to monitor whether the virtual machine is down. Function. The process is: the monitoring machine issues an access request--interface analysis request...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template