Home > Backend Development > PHP Tutorial > Application of pipe pipeline_PHP tutorial

Application of pipe pipeline_PHP tutorial

WBOY
Release: 2016-07-13 17:25:10
Original
1396 people have browsed it

Friends who use Linux must know the pipe function provided by the shell. Maybe you don’t know its full name, so have you ever used such a command:
cat INSTALL | more
This type of Command usage is developed using pipeline technology, which is different from redirection.
PHP provides the popen function to open a pipe:
int popen(string command, string mode);
popen() opens a pipe, which means opening the file pointer for processing. After opening a pipe, a file pointer is returned, and the subsequent usage is the same as reading and writing ordinary files. Take a look below:
$fp=popen("/bin/ls -l -FN /ect","r");

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

pclose($fp);
?>
You can try the output results.
Pipes are widely used. For example, we can open a sendmail pipe to send emails. Using pipes is simpler and easier to understand than using sockets. Because you must know how to interact with sendmail to use sockets, and there is no difference between preprocessing ordinary files in pipeline actions. You will understand if you look at the following program. This program will send an email to yqqfgq@china.com:
$fp=popen("/usr/sbin/sendmail yqqfgq@china. com","w");

$message="Hi! It's me, I'm 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’s easy to use! Haha, that’s all. Brothers, please contact me if you have any comments. yqqfgq@ china.com

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532084.htmlTechArticleFriends who use Linux must know the pipe (pipeline) function provided by the shell. Maybe you don’t know its full meaning yet. name, have you ever used such a command: cat INSTALL | more This type of command...
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