Application of pipe Piping _php Tutorial

Source: Internet
Author: User
A friend of Linux must know the pipe (pipe) function provided by the shell, perhaps you do not know his full name, then you have not used such a command:
Cat INSTALL | More
This type of command usage is based on the technology of the pipeline, which is different from redirection (redirection).
PHP provides the Popen function to open a pipeline:
int Popen (string command,string mode);
Popen () opens a pipe, that is, opens the handle file pointer. When a pipeline is opened, a file pointer is returned, and the next usage is the same as reading the normal file. Let's look at the following:
$FP =popen ("/bin/ls-l-fn/ect", "R");

while (!feof ($FP))
Ehco fgets ($fp, 4096). "
";

Pclose ($FP);
?>
The result of the output you try it.
Pipelines are widely used, for example, we can open a SendMail pipeline to send e-mails. Using a pipe is easier to understand than a socket. Because the socket must know how to handle with the SendMail, while the pipeline action preprocessing ordinary files is no different. Take a look at the program below and you'll see that this app will send an email to yqqfgq@china.com:
$FP =popen ("/usr/sbin/sendmail yqqfgq@china.com", "w");

$message = "hi! is me, I am yqqfgq!:) n ";

Fputs ($FP, "Subject: $subjectn");
Fputs ($fp, "from:yqqfgqn");
Fputs ($fp, "reply-to:yqqfgq@china.com");
Fputs ($fp, $message);
Fputs ($FP, ".");

Pclose ($FP);

?>
It works! Oh, so much more. Please contact me if you have any comments on our brothers. Yqqfgq@china.com

http://www.bkjia.com/PHPjc/532084.html www.bkjia.com true http://www.bkjia.com/PHPjc/532084.html techarticle a friend of Linux must know the pipe (pipe) function provided by the shell, perhaps you do not know his full name, then you use no such command: Cat INSTALL | More This type of command ...

  • 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.