PHP multi-thread Pipeline communication example

Source: Internet
Author: User
Tags fread
This article introduces the example of a pipeline communication in PHP for multithreaded programming, with the reference of a friend in need.

PHP Multi-threaded implementation of pipeline communication, the code is as follows:

     Fifopath = $fifoPath;        }//write the pipe function to start functions Open_write () {$this->w_pipe = fopen ($this->fifopath, ' W ');            if ($this->w_pipe = = NULL) {error ("Open pipe {$this->fifopath} for write error.");        return false;    } return true;    } function Write ($data) {return fwrite ($this->w_pipe, $data);        } function Write_all ($data) {$w _pipe = fopen ($this->fifopath, ' W ');        Fwrite ($w _pipe, $data);    Fclose ($w _pipe);    } function Close_write () {return fclose ($this->w_pipe);        }///Read pipeline correlation function starts function open_read () {$this->r_pipe = fopen ($this->fifopath, ' R ');            if ($this->r_pipe = = NULL) {error ("Open pipe {$this->fifopath} for read error.");        return false;    } return true;    function Read ($byte = 1024x768) {return fread ($this->r_pipe, $byte); } function Read_all () {$r _pipe = fopen ($thIs->fifopath, ' R ');        $data = ";            while (!feof ($r _pipe)) {//echo "read one k\n";        $data. = Fread ($r _pipe, 1024);        } fclose ($r _pipe);    return $data;    } function Close_read () {return fclose ($this->r_pipe); /** * Delete Pipeline * * @return Boolean is success */function Rm_pipe () {return unlink ($this-&G    T;fifopath); }}/* This class to implement a simple pipeline communication */?>

For more information on how to implement multi-threading in PHP, please refer to the following article: Understanding PHP Multi-Threading Magic PHP multithreaded Crawl web code sharing PHP Multi-threaded (do not use fork) instance sharing PHP multi-threaded class code sharing PHP support multi-Threaded Download Example

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