[PHP] Swoole in daemonize mode, chdir failure problem

Source: Internet
Author: User

Swoole version:1.9.6

In fact, it is not related to the version of Swoole, because the original code system, FPM mode, at startup, the use of the CHDIR function to change the current directory, and other code in the automatic loading of classes, are written relative to the address, not the absolute address.

The problem is, Swoole is multi-process, in daemonize mode, chdir change the current directory, in other processes is not effective, so sometimes, do not use daemonize no problem, and use daemonize will be inexplicable to find the case of the class.

The workaround is to change the directory at the same time in a few startup callbacks

$serv->on (    ' workstart ',     function ($server, $FD) {        chdir (root_path);//Assuming that the Root_path constant has been set in the preceding        /other Code        }); $serv->on (    ' tast ',     function ($server, $FD) {        chdir (root_path);//Assuming that the Root_path constant has been set earlier//        other code        

Related article: http://hongtoushizi.iteye.com/blog/2224764

Has fun with swoole!

[PHP] Swoole in daemonize mode, chdir failure problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.