Check errors in PHP file run by external url

Asked

Viewed 140 times

4

Good morning,

I am working with the service of checkout of Cielo and I’m having trouble getting treatment from url return, ie the file is called when there is an update in the payment, so I never directly access the file, it is called through the url by own Cielo.

The problem is that I’m not managing to execute some codes sql and I can’t debug them either.

When I just scan the incoming file I use this code:

$data = $_POST;
$filename = microtime(true);
$fp = fopen($filename.'.json', 'w');
fwrite($fp, json_encode($data));
fclose($fp);

This generates a file with all the data correctly. But when I try something like this:

require_once('server.php'); //Aqui está a conexão com o banco e funções de query
$query = sql('SELECT * FROM ...');

$filename = microtime(true);
$fp = fopen($filename.'.json', 'w');
fwrite($fp, json_encode($query));
fclose($fp);

No file is written on the server, so I can’t verify what’s going on.

How can I get around this problem?

  • But you want to write the JSON? file with your SQL and no screen is that, it leaves question why is using microtime? nor recommend it.

  • @Kingrider I need to get the POST data and run some SQL codes, for example, check which is the reference request and then update the payment status as received by Cielo. I don’t need to do anything with JSON, I’m just using it to write the file because it was the only way I could find to debug what’s happening in the return file. But I just need to receive the POST and make a SELECT and later an UPDATE

  • _CMCARLO: I understood if you spoke, want to post dahora, see about curl + file_get_contents to work on posting. (https://secure.php.net/manual/en/book.curl.php and https://secure.php.net/manual/en/function.file-get-contents.php)

  • You can debug generating any file with the information obtained in PHP. For example, if you want to know the contents of the $example variable, make file_put_contents($example, 'log.txt', FILE_APPEND); Thus, when the return URL is requested, it will generate a file with the contents of the $example variable and you can view it later.

1 answer

0

I went through the same situation some time ago, and I managed to debug consulting the server log files.

In addition, I used the method error_log of PHP to record custom messages in the logo file in order to facilitate debugging of errors.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.