3

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.

Oleg Patrushev
  • 255
  • 3
  • 16
  • 1
    [You look at the shutdown function in manual](http://php.net/manual/en/function.register-shutdown-function.php). – N.B. Oct 22 '14 at 14:11
  • Okay but how can I catch output or place where exit was called? – Oleg Patrushev Oct 22 '14 at 14:15
  • 1
    possible duplicate of [Can I catch exit() and die() messages?](http://stackoverflow.com/questions/3836524/can-i-catch-exit-and-die-messages) –  Oct 22 '14 at 14:18
  • ok thanks, hope it will help... but the main I need to know where exit is fired... not even output – Oleg Patrushev Oct 22 '14 at 14:23
  • @OlegPatrushev I'm the author of the QuickBooks library you're using. Specifically why do you need to know where exit; is being called? Specifically what problem are you running into that's causing you to need to know this? Can you post your code so we can see what you're doing? – Keith Palmer Jr. Oct 22 '14 at 15:10

3 Answers3

6

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.

Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
  • is an honor for me to speak with developer of so important and useful library. So at first I want to say that though library is available under packagist.org, this means that it might be compatible with 5.4 (namespaces, etc) and zf2 I think, but it is not in principle. Other side of question is that sometimes debugging takes a lot of time. Because I cant catch place where exit calls or something went wrong. Also I dont know why but sometimes after library falling it doesnt write any logs, but expected. – Oleg Patrushev Oct 24 '14 at 06:43
  • For example if I work with zf2 factory service which have a lot of properties included (for example $service = new Service(); $service->subService = new SubService(); etc), then this part of code where $callback is $service instance $Driver->log('Calling auth callback [' . $type . ']: ' . print_r($callback, true), null, QUICKBOOKS_LOG_DEVELOP); will log a lot of unnecessary info or crash without logging and any understanding why, where etc. – Oleg Patrushev Oct 24 '14 at 06:43
  • I've spent a lot of time to find this place and then changed hooks from class methods to simple functions. I think library has to be improved, developed for compatibility with 5.4 and modern frameworks like ZF2 etc. Thanks for attention! – Oleg Patrushev Oct 24 '14 at 06:44
  • Keith, can I ask you question, so how can I add to response error from my backend? For example: in my importInvoiceResponse() method list of invoices coming and if I detect that some of them does not satisfy my rules(missed, invalid params, etc), I need to show windows app's client that he has add invalid invoice and need to change something. Maybe some errorInvoiceRequest method can be used? – Oleg Patrushev Oct 24 '14 at 07:20
  • It works fine with ZF2 -- we use it all the time with that. PHP never just blows up without writing some sort of logs -- do you have PHP error logging to a file enabled? You should. Use php.net/error_log to write info to the logs so you can debug. Debugging should be quick and simple, and if it's not then you're doing something wrong. If you have more questions, a more appropriate place to ask them is on our support forums: http://www.consolibyte.com/forum/ Make sure you post your code so we can actually help you. – Keith Palmer Jr. Oct 24 '14 at 10:56
  • okay @keith-palmer-consolibyte if you think that is good so that is good) – Oleg Patrushev Oct 24 '14 at 13:20
2

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 :)

Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
  • thanks, but no benefit from this, as lib is under vendor in zf2 which will be overwritten on every composer update and its about 100500 callings of exit in lib... so anything else is needed – Oleg Patrushev Oct 22 '14 at 14:19
2

In this case you can use this function :

void register_shutdown_function ( callable $callback [, mixed $parameter [, mixed $... ]] )

it will execute a callback function just before completely exit of PHP Script
It is also accept multiple parameters with mixed types

Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
  • exit in this lib works like throw Exception... not even output I need... because exit calls as rule without message in it... I need get place where it was! – Oleg Patrushev Oct 22 '14 at 14:34