[英]PHP asynchronous page request code
i searched for a solution to make an asynchronous page request and found these lines of codes. 我搜索了提出异步页面请求的解决方案,并发现了这些代码行。 (actually i editted a little bit) (实际上我编辑了一点)
function do_the_thing()
{
$parts = parse_url("mail_sender.php");
$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80,
$errno, $errstr, 30);
$out = "POST " . $parts['path'] . " HTTP/1.1\r\n";
$out.= "Host: " . $parts['host'] . "\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
fclose($fp);
}
so i have a mail_sender.php
that sends an e-mail AUTOMATICALLY but with this asynchronous call, it doesn't send anything. 因此,我有一个mail_sender.php
可自动发送电子邮件,但通过此异步调用,它不会发送任何内容。 Am i missing somthing here? 我在这里想念东西吗? I am calling function in another page so page load continues without waiting the mail sending process. 我在另一个页面中调用函数,因此页面加载得以继续而无需等待邮件发送过程。 Only problem is, i seem to be unable to request the page or page is requested but doesn't do the job. 唯一的问题是,我似乎无法请求页面或请求页面,但没有完成任务。
Just looking at the first two lines of your function, you have a problem: 仅查看函数的前两行,就会遇到问题:
parse_url("mail_sender.php")
gives you an array with one element ( see example ): parse_url("mail_sender.php")
为您提供了一个包含一个元素的数组( 请参见示例 ):
array(1) {
["path"]=>
string(15) "mail_sender.php"
}
So you are calling fsockopen
without the first - required - parameter. 因此,您在调用fsockopen
没有第一个-必需-参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.