NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Debug script invoked as a callback by WorldPay or PayPal


Joined: 20 Jun 2007
Posts: 5
Reply with quote
hello,

I am trying to debug PHP script that is invoked asynchronously by an external HTTP call (in this case it is PayPal IPN). Although i place a breakpoint in the code and also tried placing a DebugBreak() statement, PHPED does not break in that script when it is invoked. How do i set up PHPED in this scenario so that i can debug this code?

cheers
View user's profileFind all posts by posseadesseSend private message
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
On a DebugBreak statement the debug session is attempted on the IP that the request came in from. In your case probably the external IP.
Since the debug listener usually listens on the internal lan only, you might want to add the IP of the debugging PC to the call like so:

DebugBreak ( '1@192.168.1.1' );

That is if your pc is on IP 192.168.1.1 of course... if not change into the correct value. The 1 would be the debug session id.
If the request comes in on the same PC as the debugger you can also use 127.0.0.1 obviously Smile
View user's profileFind all posts by BlizzSend private messageVisit poster's website


Joined: 20 Jun 2007
Posts: 5
Reply with quote
Blizz, thanks for the swift response Smile
i am not sure that i understand your suggestion, perhaps i should describe my environment.

i am doing my development and testing on my home PC. i allow external HTTP requests to be routed to my PC. I am using PayPal's Instant Payment Notification with my 3rd party shopping cart. After customers press checkout, they are transfered to paypal (using HTTP POST) to complete the payment. Aside from the shopping cart details, the HTTP POST (to paypal) includes the URL that paypal should call when the transaction completed. In an asynchronous fashion, Paypal calls the URL i provided.

I would like to be able to debug my PHP code as it is invoked when Paypal call it. I need help to set up PHPED to break in the code when it is called by paypal.

thanks a lot
View user's profileFind all posts by posseadesseSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
I would like to be able to debug my PHP code as it is invoked when Paypal call it. I need help to set up PHPED to break in the code when it is called by paypal.

Blizz is correct with his suggestion.
You may want to insert DebugBreak() into the code that is called when PayPal posts to the URL.
But you also need to provide debugger a way to use your address instead of the address it will detect from the caller IP. That's why you have to specify your own IP where you run DbgListener.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 20 Jun 2007
Posts: 5
Reply with quote
Dmitri, Blizz,

The syntax for debugbreak() is SESSIONID@IPADDRESS:PORT - is that correct? if so, here are a couple of questions...
1. How do i know what the SESSIONID is if Paypal is the one that invokes the PHP script?
2. What IPADDRESS should i use? is it the NAT address of my PC or the address of PayPal's server who called me?
3. do i have to specify the PORT or this be left out? if needed, what port number should i use?

thanks for your patience
Alon
View user's profileFind all posts by posseadesseSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
DebugBreak accepts the same string as passed with DBGSESSID that triggers debug session if sent with GET, POST or cookies. This page describes DBGSESSID syntax: http://forum.nusphere.com/faq-what-is-dbgsessid-syntax-t586.html
Shortly, yes it should be something like SESSIONID[@IPADDRESORHOSTNAME[:PORT]]
(I used square brackets to depict optional parameters)
SESSIONID - feel free to use ANY positive numbers (negative are used to drop cookie)
IPADDRESORHOSTNAME - is IP address or hostname of the machine where you run DbgListener and IDE (so it's your client machine).
PORT is port used for DbgListener.

If there is a NAT router between your client machine and host (server) where you run PHP, you have the following two ways to follow:
- set port forwarding on your NAT router and EXTERNAL port and EXTERNAL ip is what you need to have in the argument for DebugBreak while INTERNAL ones won't be used anywhere except router configuration.
- run SSH tunnel using putty or openssh client and specify localhost or 127.0.0.1 as hostname for DebugBreak.

See FAQ topics below:
http://forum.nusphere.com/howto-run-debug-session-through-ssh-t580.html
http://forum.nusphere.com/tip-troubleshooting-debugger-communications-t579.html
http://forum.nusphere.com/howto-run-debug-session-t585.html
http://forum.nusphere.com/tip-troubleshooting-debugger-communications-ssh-t581.html

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 20 Jun 2007
Posts: 5
Reply with quote
OK, i finally got debugbreak to work and i now understand the communication paths needed to make it work.
Having said that, i was not able to make it work with PayPal IPN. [If my understanding of the DBG communication is correct] PayPal probably has port 7869 blocked so that DBG session setup never completes. in fact, i can tell that debugbreak really stops the code from executing, but phpED does not actually gets engaged and stops in the code. nothing really happens other than the fact that the code lines after debugbreak() don't get executed.

is there another way that you may suggest?

thanks so much
Alon
View user's profileFind all posts by posseadesseSend private message
Veteran

Joined: 24 Jan 2006
Posts: 311
Reply with quote
You may look into running dbg over ssh:
http://www.nusphere.com/kb/technicalfaq/php_debugger_ssh.htm
View user's profileFind all posts by yfaktorSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
OK, i finally got debugbreak to work and i now understand the communication paths needed to make it work

great.
Quote:
Having said that, i was not able to make it work with PayPal IPN

as far as I know, PayPal informs you about transactions by running URL that you provided to them. If this URL points to the same site/hostname where you got debugger to work, it is supposed to work.
Quote:
PayPal probably has port 7869 blocked

they can block that port on their own sites, not on yours.
If anybody blocked that port, you would not get debugger to work.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 06 Jun 2007
Posts: 289
Location: Vancouver, Canada
Reply with quote
When I first read over this thread, I shook my head and thought by myself that this could not be possible. Debugging a script called by a third party? No ways. And then I read it again and it started to make sense Embarassed

I have now successfully debugged an asynchronous callback from WorldPay. I have not tried a PayPal callback yet, but it I see no reason why it will not work as well. I did have some minor problems with things on the WorldPay side timing out after 60 seconds, but that did not prevent me from completing some lengthy debug sessions.

For the record, I am debugging the script on a remote server via an SSH tunnel, and I am invoking the debug session with the DebugBreak ( '1@192.168.1.1' ); statement suggested by Blizz.

Very well done Nusphere, PhpED rocks Very Happy

_________________
Smile
View user's profileFind all posts by annoSend private messageVisit poster's website
Debug script invoked as a callback by WorldPay or PayPal
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic