gkralik / php7-sapnwrfc

SAP NW RFC SDK extension for PHP 7.3+ & PHP 8
https://gkralik.github.io/php7-sapnwrfc
MIT License
90 stars 35 forks source link

Exceptions don't work #121

Closed Romanm745 closed 2 years ago

Romanm745 commented 2 years ago

Question

Hello, I have an exception catcher set up in my program, but I still can't catch any exceptions. Instead, I get a broken website ERR_EMPTY_RESPONSE. Sometimes when I test something, I just get a broken page and I don't know the reason.

                 try { 
                        $str=sprintf('%010d', $_POST['stredisko']);
                        $c = new SAPNWRFC\Connection($parameters,$options);
                        $f = $c->getFunction('Z_VM_GET_STR');
                        \SAPNWRFC\clearFunctionDescCache('Z_VM_GET_STR');
                        $result = $f->invoke(['STREDISKO' => $str,'IM' => $_POST['druh_im'],]);
                        $majetok=$result['ZVMP_STR'];
                        }catch(SapException $ex) {
                                                                 echo 'Exception: ' . $ex->getMessage() . PHP_EOL;
                                                                  }
Version | 1.3.0-41-g725240b -- | -- SAP NW RFC SDK | 7500.0.7

Thank you for help.

gkralik commented 2 years ago

Have you tried with the latest version in main - tag 2.0.0-beta1?

Romanm745 commented 2 years ago

I installed the latest version, but now I can't cause application crash. In version 1.3, I simply made a mistake when transferring text with special characters, where there was a problem with allocating a sufficient amount of memory. Is there any way to artificially throw an exception in version 2.0.0?

Romanm745 commented 2 years ago

BTW, error tracing does not work either. No file is generated. Of course, the trace parameter is set. 'trace' => SapConnection::TRACE_LEVEL_FULL,

gkralik commented 2 years ago

Please provide a full example to reproduce, along with the exact PHP version your are using.

gkralik commented 2 years ago

Below is a full example triggering an exception and logging to a trace file:

<?php

use \SAPNWRFC\Connection as SapConnection;
use \SAPNWRFC\Exception as SapException;

$config = [ /* ... */ ];

try {
    // by default, the trace file is created in the current working directory.
    // the location can be changed though:
    SapConnection::setTraceDir(__DIR__);

    $c = new SapConnection(array_merge($config, [
        'trace' => SapConnection::TRACE_LEVEL_VERBOSE
    ]));

    // this will throw an exception because the function module does not exist
    $f = $c->getFunction('Z_NON_EXISTING_FM');

} catch (SapException $ex) {
    echo "Exception: {$ex->getMessage()}\n";
}

Tested with the following versions:

PHP version: 8.0.2
php-sapnwrfc version: 2.0.0-beta1
NW RFC SDK version: 7500.0.8
gkralik commented 2 years ago

Closing this for lack of a response.