【发布时间】:2013-11-29 21:51:52
【问题描述】:
我想通过登录脚本发送一封包含自动内容的电子邮件,但发送时应该延迟一些(随机)秒(用于发送密钥对的一部分)。
这就是为什么我尝试使用通常有效的 curl,而不是使用“include”或类,但主脚本不必等到 sleep() 结束。
主要代码是(简单卷曲代码) 玩弄“CURLOPT_MUTE,1”和“CURLOPT_RETURNTRANSFER,false”根本不起作用。
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://domain/path/to/delayed_mail.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'to=' . $to . '&from=' . $from . '&subject=...');
curl_exec ($ch);
curl_close ($ch);
?>
delayed_mail.php 看起来像这样
<?php
//path to mail class
//some POST and GET REQUEST filters and authentications
//with $_REQ[$key]=$value; as output
$delay = rand(2,32);
sleep($delay);
$ddlab->mail->html($_REQ['to'],$_REQ['from'],...,$_REQ['options']);
?>
正如我上面提到的,我有点卡住了。用于 html 输出的主脚本,在 sleep() 之后,不应等待,直到发送电子邮件。
第一个问题:如何独立执行“delayed_mail.php”(随时发送电子邮件,但让我的脚本运行!)
第二个问题:如何设置内部路径,例如 '../../delayed_mail.php' 或 getcwd().'/delayed_mail.php' (两者似乎都不起作用)而不是完整的“ http://"-URL ?
感谢您的努力。
【问题讨论】:
-
我的问题可能包括“有没有其他方法可以代替使用 curl 来达到与描述相同的结果?”
标签: php curl sleep delayed-execution