贝宝IPN脚本,feof和fgets问题 [英] Paypal IPN Script, issue with feof and fgets

查看:114
本文介绍了贝宝IPN脚本,feof和fgets问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来,我的Paypal IPN侦听器脚本一直出现问题.对于那些不熟悉Paypal IPN系统的人,基本上Paypal会向您的脚本发送有关交易的消息,然后再添加一些附加位,将其发送回去.如果Paypal收到正确的答复,它将以'VERIFIED'答复,否则,将显示'INVALID'.

I've been having issues with my Paypal IPN listener script for a couple of days now. For those of you who are unfamiliar with the Paypal IPN system, basically Paypal sends your script with a message about the transaction, which you send back with a couple of bits added. If Paypal receives the correct reply, it'll reply with 'VERIFIED', and if not it'll say 'INVALID'.

我最初以为我遇到的问题是与"fsockopen"命令有关: $ fp = fsockopen('ssl://sandbox.paypal.com',443,$ errno,$ errstr,30); 但是,将我所有的代码都减少到了这一行,看来一切正常.问题来自"feof"和"fgets"命令.脚本只是挂断了,我不知道为什么.我基本上已经复制了Paypal IPN侦听器网站上建议的代码,因此我认为它可以工作!如果您能帮助我理解为什么feof或fgets导致其停顿,那么您的帮助将不胜感激.

I initially thought that the problem I was experiencing was with the 'fsockopen' command: $fp=fsockopen('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30); However, having reduced all of my code to pretty much just this line, it seems to connect ok. The problem comes in with the 'feof' and 'fgets' commands. The script just hangs up, and I don't know why. I've essentially copied the code suggested on the Paypal IPN Listener website, so I assumed that it would work! If you could help me understand why feof or fgets are causing it to stall then your help would be much appreciated.

这是完整的脚本:

$postback = 'cmd=_notify-validate'; //doesn't matter what these include for now
$header='abc';

//Script has been activated, create debug
$filename = 'debug/debug1_script.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle,$postback);
fclose($filehandle);


$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection

//no connection, create debug file
if(!$fp){
    $filename = 'debug/debug2_fpfail.txt';
    $filehandle=fopen($filename, 'w');
    fwrite($filehandle, $errstr.'('.$errno.')');
    fclose($filehandle);
    die();
}


//post data back
fputs($fp, $header . $postback);

//create debug file
$filename = 'debug/debug3_postback.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle, $header.$postback);
fclose($filehandle);


//script hangs with either of the two following lines included
while(!feof($fp)){
    $res=fgets($fp,1024);
}

非常感谢!

推荐答案

所以我想我找到了一个解决方案,而不是使用

So I think I found a solution, which was instead of using the

while(!feof())

fgets()

combo,我用这个:

combo, I used this:

$res=stream_get_contents($fp, 1024);

第一次工作!现在我可以继续生活了.

Worked first time! Now I can get on with my life.

这篇关于贝宝IPN脚本,feof和fgets问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆