rgb192
asked on
write screen output to text file
[CODE]
<?php
ini_set('display_errors', TRUE);
error_reporting(-1);
require('PaypalIPN.php');
use \PaypalIPN;
$ipn = new PaypalIPN();
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
[/CODE]
How can i write screen output (what i see on google chrome browser screen)
to text file
<?php
ini_set('display_errors', TRUE);
error_reporting(-1);
require('PaypalIPN.php');
use \PaypalIPN;
$ipn = new PaypalIPN();
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
[/CODE]
How can i write screen output (what i see on google chrome browser screen)
to text file
ASKER
Do I put at top of file
If the script fails for any reason before the output buffers can be written, you may be able to find the reason for the failure in the error_log file. Basically, output buffering is only useful for diagnostics if your script runs from beginning to end. Your output buffers will capture any echo output and any PHP messages of the Notice and Warning levels. A parse error or a fatal error may cause the output buffers to be flushed to the stdout at end of job. This is not useful if there is no browser to display the stdout information!
Yes, generally speaking, you would put ob_start() at the logical top of the script, and capture the buffers with ob_get_clean() at the logical bottom of the script.
ASKER
<?php
ob_start();
ini_set('display_errors', TRUE);
error_reporting(-1);
require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
// End output buffering and get output buffer
$buffer = ob_get_clean();
// Write it to a file
file_put_contents('yourfile.txt', $buffer);
I think I would try it more like this. Untested code, but probably correct in principle.
<?php
ob_start();
ini_set('display_errors', TRUE);
error_reporting(-1);
// MAKE SURE THERE IS SOMETHING IN THE BUFFER
echo 'Hello World' . PHP_EOL;
require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
// SHOW THE OBJECT
var_dump($ipn);
// Use the sandbox endpoint during testing.
$ipn->useSandbox();
$verified = $ipn->verifyIPN();
if ($verified) {
// SHOW VERIFIED
echo PHP_EOL . "Verified";
/*
* Process IPN
* A list of variables is available here:
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
*/
}
else {
echo PHP_EOL . "Not Verified";
}
// End output buffering and get output buffer
$buffer = ob_get_clean();
// Write it to a file
file_put_contents('yourfile.txt', $buffer);
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");
ASKER
Hello World object(PaypalIPN)#1 (2) { ["use_sandbox":"PaypalIPN":private]=> bool(false) ["use_local_certs":"PaypalIPN":private]=> bool(true) }
Fatal error: Uncaught Exception: Missing POST Data in /server/Paypal/PaypalIPN.php:60 Stack trace: #0 /server/Paypal/example_usage.php(18): PaypalIPN->verifyIPN() #1 {main} thrown in /server/Paypal/PaypalIPN.php on line 60
I tried pointing paypal ipn to both servers and running example_usage.php
no .txt file was created in directory
paypal.com
instant payment notification (IPN) history
status
sent
failed
retrying
Disabled-Resending
now close to 100 lines
I am not sure if 'sent' is new
but this may be progress because some rows have a column with word 'sent'
I am confused by this statement
Also it appears there is an error in your code
no .txt file was created in directoryWhere did the output you posted come from?
Also it appears there is an error in your code
Fatal error: Uncaught Exception: Missing POST Data in /server/Paypal/PaypalIPN.php:60 Stack trace: #0 /server/Paypal/example_usage.php(18): PaypalIPN->verifyIPN() #1 {main} thrown in /server/Paypal/PaypalIPN.php on line 60
ASKER
uncaught error missing post.
every time i send paypal ipn using PayPal.com there will be 1 post.
i can not see this post by running example_usage.php on browser
when i look for newly written txt file everywhere on webserver. i can not find
every time i send paypal ipn using PayPal.com there will be 1 post.
i can not see this post by running example_usage.php on browser
when i look for newly written txt file everywhere on webserver. i can not find
ASKER
// Write it to a file
file_put_contents('yourfil e.txt', $buffer);
i can not find
yourfile.txt
maybe i need to create first
and buffer will add lines
file_put_contents('yourfil
i can not find
yourfile.txt
maybe i need to create first
and buffer will add lines
ASKER
i created
yourfile.txt
ran EXAMPLE_USAGE.PHP
on both linux shared servers
sent paypal ipn to both shared linux servers
yourfile.txt still blank empty
yourfile.txt
ran EXAMPLE_USAGE.PHP
on both linux shared servers
sent paypal ipn to both shared linux servers
yourfile.txt still blank empty
Lets go back a bit - what in the code is producing output?
Based on your original post - what are you expecting to see from that code?
Also, can you explain the full process of how you run your test.
Also, can you explain the full process of how you run your test.
Reformatted a bit for readability, here's the output buffer.
var_dump() output at line 14
Stack trace points to line 18 of your script and line 60 of PayPalIPN.php
As I recall, the PayPal IPN expects a sequence as follows:
1. It's started by a POST request from PayPal
2. It receives POST request variables
3. It adds something like cmd_verify to the end of the POST variables
4. It turns around and sends the POST variables with cmd_verify back to PayPal
5. It receives a response from PayPal indicating Verified.
I did not see anything in your code that deals with the POST variables, and this might be the cause of the Missing POST Data exception.
Hello World
object(PaypalIPN)#1 (2)
{ ["use_sandbox":"PaypalIPN":private]=> bool(false)
["use_local_certs":"PaypalIPN":private]=> bool(true)
}
Fatal error: Uncaught Exception: Missing POST Data in /server/Paypal/PaypalIPN.php:60
Stack trace: #0 /server/Paypal/example_usage.php(18): PaypalIPN->verifyIPN() #1 {main} thrown in /server/Paypal/PaypalIPN.php on line 60
Hello World comes from your script at line 7var_dump() output at line 14
Stack trace points to line 18 of your script and line 60 of PayPalIPN.php
As I recall, the PayPal IPN expects a sequence as follows:
1. It's started by a POST request from PayPal
2. It receives POST request variables
3. It adds something like cmd_verify to the end of the POST variables
4. It turns around and sends the POST variables with cmd_verify back to PayPal
5. It receives a response from PayPal indicating Verified.
I did not see anything in your code that deals with the POST variables, and this might be the cause of the Missing POST Data exception.
ASKER
So the only way i can test adding rows to yourfile.txt is through a paypal post?
Running EXAMPLE_USAGE.PHP on a browser will not add rows to yourfile.txt
Running EXAMPLE_USAGE.PHP on a browser will not add rows to yourfile.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So the only way i can test adding rows to yourfile.txt is through a paypal post?It's been a long time since I actively worked with PayPal, but I believe that they have a testing setup you can trigger on demand.
Also, the strategy of using the output buffers may have a risk - if the script fails before it captures the output buffers and writes them into yourfile.txt, you won't get the debugging information you need. Suggest you try writing the debugging information with error_log(), then go look into the log to find the information. The tail command works very well with the error_log() strategy.
ASKER
testing setup you can trigger on demand.I can resend paypal payments received by going to paypal.com in the ipn section
Suggest you try writing the debugging information with error_log(), then go look into the log to find the information. The tail command works very well with the error_log() strategy.I can not see this in shared linux server
what do you see in the browser - that is all that will be written to the output file.yes when I use a windows 10 desktop browser
wysiwyg
but I will never see the browser output the 1 second when paypal resends payment information initiated when I am logged onto paypal.com and I click "resend ipn to ipn url"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
I would prefer editing example_usage.php instead of important file
and creating a txt log in same directory. (avoiding the conventional error log).
I know my request is a work around; but I think it would help me learn.
So I will open a related question
I would prefer editing example_usage.php instead of important file
and creating a txt log in same directory. (avoiding the conventional error log).
I know my request is a work around; but I think it would help me learn.
So I will open a related question
See also:
https://www.experts-exchange.com/questions/28999622/error-log-using-ftp.html?anchorAnswerId=41990777#a41990777
Things are looking good, and you can get to the error log with FTP or even a browser.
https://www.experts-exchange.com/questions/28999622/error-log-using-ftp.html?anchorAnswerId=41990777#a41990777
Things are looking good, and you can get to the error log with FTP or even a browser.
ob_start()
ob_get_clean();
Open in new window