SOLVED: The problem was in the Java code line: if(APIRequest.checkIP(incomingIP, incomingHostname)) { }
Turns out the API request to check if the IP is in the list of allowed IPs took too long which caused the PHP script to timeout.