Php successfully calls the Linux Command, but the function does not return [resolved]

Source: Internet
Author: User
Yesterday, the Network Storage System developed by the lab encountered a BUG. [Problem description] php uses the exec function to call the Linux Command servicesmbrestart (restart the Samba Service). After normal restart, the exec function returns the status code 0 immediately, however, after the underlying layer was restarted normally yesterday, the exec function was delayed, causing program execution to get stuck here.

Yesterday, the Network Storage System developed by the lab encountered a BUG. [Problem description] php uses the exec function to call the Linux Command service smb restart (restart the Samba service). After normal restart, the exec function returns the status code 0 immediately, however, after the underlying layer was restarted normally yesterday, the exec function was delayed, causing program execution to get stuck here.

Yesterday, the Network Storage System developed by the lab encountered a BUG.

[Problem description]

Php uses the exec function to call the Linux Command "service smb restart" (restart Samba service). After normal restart, the exec function returns the status code 0 immediately, however, after the underlying layer was restarted normally yesterday, the exec function was delayed, causing program execution to get stuck here.

[Solution]

(1) At first, I was wondering what caused the samba service to fail to be restarted. After further experiments, we found that through our network storage system, the samba service can be shut down normally, however, the enabling and restarting operations cannot be performed normally. In addition, the command to enable and restart the service can be executed and returned normally on the underlying Linux console. Based on the above experiment, I guess the problem may be related to permissions related to php and samba services. Later, I checked samba configuration files, directory permissions, and openldap, a samba-related user permission management tool. No obvious problems were found (excluding omissions ).

(2) Later, I thought of the History CT script that I used to monitor the execution time of a command and forcibly terminate it after the timeout. Encapsulate the samba service restart command using the reset CT script and set the timeout. Then, run the script separately to forcibly return the result after the specified timeout, however, our network storage system still cannot return normally when executing this script.

(3) Finally, I started with the exec function. After investigation, I finally switched to the proc_open and proc_close functions (to open and close a process channel) php code: proc_close (proc_open ("service smb restart", $ output, $ ret ));


At this point, the BUG of yesterday has been bypassed, but I still don't quite understand why this problem occurs. If a friend has encountered a similar situation, please share your experience ~

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.