Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch or prevent calling of exit, die

Tags:

php

quickbooks

I work with QuickBooks for windows. And windows app makes call to my backend where in some library script it call exit or die... So I cant catch response and need to detect where exit runs or catch output before exit. For example

try{
    $lib->run();
} catch on exit ($output) {
    log($output);
}

so maybe anyone knows it calls exit when I enable QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS hook... And debugger shows that it dont enter my function on hook... So it dies before.

like image 809
Oleg Patrushev Avatar asked Oct 23 '25 16:10

Oleg Patrushev


2 Answers

I'm the author of the QuickBooks library (https://github.com/consolibyte/quickbooks-php) that you're using.

The library calls exit()/die() for a very good reason -- because if you do anything after the point it calls exit/die at, you'll corrupt the SOAP output and logging of the library and break your QuickBooks integration. There are many, many hook points built into the library specifically to allow you to do any variety of things without having to worry about the calls to exit or die.

Based on what you've said, there's about a 99.9% chance that you're doing something you shouldn't be in the code, or you have PHP or SQL error in your code that you're not seeing.

Post your code, and give us an idea of why you think you need to catch the call to exit/die, and I can edit my question to help you out further.

like image 187
Keith Palmer Jr. Avatar answered Oct 25 '25 05:10

Keith Palmer Jr.


It is not possible to prevent the execution of exit
The tips is to write your own exit function like this example :

customExit($output){
    log($output);
    exit;
}

after that you have to search end replace all of exit occurances of PHP language construct, and replace them by customExit($output) function

Hope it helps :)

like image 20
Halayem Anis Avatar answered Oct 25 '25 06:10

Halayem Anis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!