PHP Operations Shee Learning notes (a) PHP operation Shell function

Source: Internet
Author: User

First, PHP operation Shell

1. System function: Execute common command

String System (String $command [, int & $return _var])

1) $command is the command string

2) $return _var return status is 0 or not 0

3) function eventually returns a string

Cases:

$shell = "ls"; Ifconfig, FREE-M, etc.

System ($shell, $s);

Echo $s;

2. exec function: return array result

String exec (string $command [, Array & $output [, int & $return _var]])

1) $command is the command string

2) $output to return an array

3) $return _var for return shaping state value of 0 or not 0

Cases:

$shell = "Free-m";

EXEC ($shell, $arr, $s);

Var_dump ($arr);

Echo $s;

3. Commands that require root authority to execute

1) The sudo command to elevate the Apache daemon

A, note the sudo command must be executed from the TTY terminal: Visudo

#Defaults Requiretty

B. Visudo command to set sudo permissions

Daemon all=nopasswd:/usr/sbin/useradd,/usr/sbin/init,/usr/sbin/userdel,/usr/bin/passwd

2) Execute the command in PHP

EXEC ("sudo useradd user1", $status);

Echo $status;

Change Password: $shell = "Echo 123 | sudo passwd--stdin user ";

PHP Operations Shee Learning notes (a) PHP operation Shell function

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.