如何将 Imap 连接从 PHP Imap 库从 PHP/JQuery 传递到 PHP 文件
我希望能够使用 Jquery 将名为 $connection 的 Imap 文件从 1 个 php 文件传递到另一个 php 文件。问题是,它不会作为对象传递,而是转换为名为资源的字符串 #54 - 有没有可能的方法将 Imap Connection 对象传递到另一个 PHP 文件?我确实需要保持此连接打开,因为如果我反复关闭它并打开新连接,Hotmail 和 Yahoo 等提供商会将我们锁定 15-30 分钟。
这是我当前的代码 Jquery w/ PHP 变量混合:
var dataString='server=<?php echo $server; ?>&email=<?php echo $email_address; ?>&connection=<?php echo $connection; ?>&password=<?php echo $password; ?>&server=<?php echo $server;?>&daysago='+daysago+'&num='+num;
$.ajax({
type: "POST",
url: "fastsearch.php",
data: dataString,
success: function(msg){
Is it possible or conceivable to pass this variable to a php file using jquery or other other than jquery?如果没有,我有哪些解决方法?是否可以在不结束 PHP 文件的情况下显示结果?
这是有关 imap_open 和 imap_open 的更多信息imap 流对象:
I would like to be able to pass a an Imap file named $connection from 1 php file to another php file using Jquery. The issue is, It doesn't pass as the object, it gets converted to a string called resource #54 - Is there any possible way to pass the Imap Connection object to another PHP file? I really need to keep this connection open because if I repeatedly close it and open new connections, providers such as Hotmail and Yahoo lock us out for 15-30 minutes.
Here's my current code Jquery w/ PHP variables mixed in:
var dataString='server=<?php echo $server; ?>&email=<?php echo $email_address; ?>&connection=<?php echo $connection; ?>&password=<?php echo $password; ?>&server=<?php echo $server;?>&daysago='+daysago+'&num='+num;
$.ajax({
type: "POST",
url: "fastsearch.php",
data: dataString,
success: function(msg){
Is it possible or conceivable to pass this variable to a php file using jquery or something other than jquery? If not, what are my options for a workaround? Is it possible to display results without ending a PHP file?
Here's more info on imap_open & the imap stream object:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在脚本之间“传递”连接,因为它们是在单独的服务器进程下生成的,因此在完成后没有对其的引用。您需要做的是使用 pfsockopen< 打开与 imap 服务器的持久连接/a>:
然后,您将手动构建基本的 imap 命令并使用
fputs
发送到打开的连接:等等。
You cannot "pass" a connection between scripts as they are spawned under seperate server processes so after it completes there is no reference to it. What you need to do is open up a persistent connection to the imap server using pfsockopen:
You will then construct the essential imap commands by hand and use
fputs
to post to the open connection:and so on.
您无法在不同的 PHP 脚本实例之间传递资源。
韦斯的答案是正确的 - 但请阅读讨论。
如果是我,我会使用守护进程/计划作业来获取邮件 - 虽然您可以用 PHP 编写自己的邮件,但我只会使用 fetchmail 和 cron 从远程系统获取电子邮件,然后将其镜像到本地邮箱或通过 procmail 提供。
You can't pass resources between separate instances of PHP scripts.
The answer by Wes is sort of correct - but do read the discussion.
If it were me I'd use a daemon/scheduled job to fetch the mail - while you could write your own in PHP, I'd just use fetchmail and cron to get the email off the remote system then either mirror it in a local mailbox or feed it through procmail.