Home > Backend Development > PHP Tutorial > php fsockopen 并发,该怎么解决

php fsockopen 并发,该怎么解决

WBOY
Release: 2016-06-13 12:56:07
Original
961 people have browsed it

php fsockopen 并发
求教 fsockopen  并发。
我想发邮件  不知道 fsockopen  这个怎么并发邮件


------解决方案--------------------
你可以ajax循环执行发送邮件,也可以用下面两个方法(西面代码是大致思路):

if (isset($_GET['act']) && $_GET['act'] == 'sendMail') {<br />
    sendEmail();// 发送邮件操作<br />
}<br />
<br />
function fSockGet($url, $timeout = 3)<br />
{<br />
    $info = parse_url($url);<br />
    extract($info);<br />
    $query = isset($query) ? trim($query) : '';<br />
    $path = isset($path) ? trim($path) : '';<br />
<br />
    $fp = fsockopen($host, 80, $errno, $errstr, $timeout);<br />
    if (!$fp) {<br />
        exit("$errstr ($errno)<br>\n");<br />
    }<br />
<br />
    $write = fwrite($fp, "GET {$path}?{$query} HTTP/1.0\r\nHost: {$host}\r\n\r\n");<br />
<br />
//    while (!feof($fp)) {<br />
//        echo fread($fp, 4096);<br />
//    }<br />
}<br />
<br />
<br />
$url = "http://mydir.com/index.php?act=sendMail";<br />
$emailList = array(...);<br />
foreach ($emailList as $email) {<br />
    fSockGet($url);<br />
}
Copy after login
Related labels:
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