2

I have a script that is being called by a 3rd party script, but it doesn't work. I can see in the logs that the file is in fact being called, just nothing happends.

How do you debug a file called by a 3rd party?

  • I can't call the file from the commandline / another file, due to security checks
  • The 3rd party is an automated process, I can not ask them for help
  • I do not know if the code works properly, doesn't do a thing, or it has an error
    • This is an older site (or consider a less pro website), proper errorhandling does not exist

Best solution thusfar:
Place a bunch of file_put_contents($loc.'/a-1.txt', '') (where the 1 increments every time used) and see how many files are created/updated when you let the script excecute.
This is slow, and only gives me how the code flows, not actual errors, so this isn't very efficient.

I've found some topics talking about changing STDIN, STDOUT and STDERR, but I can't seem to get those to work out of the box.

5
  • "proper errorhandling does not exist" - is there an error log? How are errors in the script currently handled? Are you saying you can't run the code at all - no way to actually test it?
    – MrWhite
    Dec 2 '15 at 12:02
  • A log just for php errors/warnings? Not that I know of. They are currently handled in a manner it shouldn't, a bunch of die()'s. This is an older website, error handling wasnt really a thing in this version. I can't just run the code, I need it to come from the 3rd party. This is kind of a bad case scenario, I'm running very blind, even a lighter would be great.
    – Martijn
    Dec 2 '15 at 12:34
  • "A bunch of die()" is not error handling. If it's not too much, I'd recommend showing your code at stackoverflow.com, there you can easily find some excellent pointers about how you can debug the script without having it called from the 3rd party site. As a first step solution, I'd recommend adding bunch of file_put_contents instead of die() and in the text going to the file, place values of all the variables you have till that point. This will give you insights about what exactly is going in the script.
    – Prateek
    Dec 3 '15 at 6:10
  • This part is handling payments from a bank (it's a webshop). Posting code will not help as it's a lot of code, and only errors when the bank calls the file (so it depends on something). The file contents method is the one I used for the situation which led me to this topic, but it ain't fast.
    – Martijn
    Dec 3 '15 at 8:07
  • Yes, that wouldn't be fast but if you place your file statements at correct places, you'd be closer to the cause of error with every call.
    – Prateek
    Dec 3 '15 at 11:01
1

This is one of the absolute worst case scenarios when inhereting a web project that is old, poorly designed, badly documented, and can't easily be debugged. Any code at all let alone mission critical autonomous code like this should be well documented and have thorough error reporting. Assuming this has been done in a language like PHP you can increase the error logging level to informational which will show every last error message that may be generated by the server. This will report on any errors that are being handled by the language and not the code. The next step would be to go through the code and identify anywhere that the code outputs any data to the connection (assuming a http style connection any data that is effectively "printed" to the buffer for outputting) and add logging so all the data is logged to file. If you add each instance of data output to an array with details on the line it was generated at you can push all data to to a file one time during each request to the web service to minimise file writes causing delays and then read through what is being sent back to the bank.

It is going to be extremely difficult and complicated but there is not much more that can be done in the short term to identify the problem. In the long term you should absolutely be going through the code and implementing sanity checks, data validation, and error logging and reporting. Basically anything that will prevent the code from running should be logged in a manner that will let you go through and find out not just what the error was but what could have caused the error, the data being worked on, and what line the error occurred on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.