Random class not found fatal errors

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
JuanMdP
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 06, 2018 9:08 am

Tue Feb 06, 2018 11:25 am

Greetings,

I work at a hospital where we've developed an app that covers a lot of ground for it, it used to run on a regular PC with high specs until we finally got a server. But that's where we began running into several issues, the most troubling one is the one mentioned in the title. When I say random I mean random, like, we have an include file with 20 classes and one, just one, at random will suddenly stop being detected. More curious is the fact that if I were to include that missing class right after the include file with all the classes:

ie:
require_once("classes.php");

will throw a fatal error with a class missing but

require_once("classes.php");
require_once("missing class.php");

works.

The "solution" so far has been to restart the webserver, unfortunately it's running on IIS but the settings are verbatim of the ones from the PC where it worked without hitches, the settings for PHP are the same from the PHP on the PC where it worked fine too. On one hand it makes me think it could be a webserver issue but on the other hand, this particular issue does not leave any kind of error or warning on the Windows' event viewer.

To be honest, this particular issue is driving me nuts so any kind of feedback or ideas on what could the issue be would be greatly appreciated.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Tue Feb 06, 2018 11:52 am

You'll find errors in the php error log so long as error reporting is switched to do so. The error will give you line numbers etc. so that you can start to trace where the problem is.

The version of PHP you are using might make a difference, are you using the same version on your server as you did on the PC?

JuanMdP
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 06, 2018 9:08 am

Tue Feb 06, 2018 1:38 pm

That's another thing, I've error reporting on and I check it religiously to make sure there's nothing wrong with the app causing some kind of consumption spike. At the time of this happening (and it's been the same for the other occurrences) there's nothing there other than the class not found fatal errors (and as mentioned on the OP, it's always just one class at random). There are no other errors preceeding this that could even make me think something else is triggering it.

As for the PHP version, they aren't the same. We used to run 5.3 and now it's on 5.5.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Tue Feb 06, 2018 4:27 pm

There have been quite a few changes; what you'll have to do is go through your scripts and check what has changed in the manual.

Even better if you can, would be to upgrade to v7: php 5.5 is no longer supported, 5.6 support will end at the end of this year. It might mean a bit more work, but you currently have to make changes to get your scripts working; in the long run it would be far easier and certainly more secure.

JuanMdP
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 06, 2018 9:08 am

Wed Feb 07, 2018 3:06 am

I'll give the changes a read but I can't help but feel I'm just dodging the issue which is to find why I have a random issue that happens every couple of days. I can't see this being a problem with the PHP version.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Wed Feb 07, 2018 8:31 am

More recent versions have tightened up and changed / deprecated some things. You may have been getting warnings before, but now you are getting fatal errors.

As said, there have been a lot of changes. I still suggest you seriously look at upgrading to PHP 7 as you will be getting problems in the near future if you don't at least prepare for it. PHP 7 is much faster and more secure along with vastly improved oop features.

JuanMdP
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 06, 2018 9:08 am

Wed Feb 07, 2018 11:06 am

But I'm not getting a fixed fatal error, it's not that something is giving me a fatal error no matter what. It's that I'm very, very occassionally getting a fatal error on a file not found (which is always different) that does exist and it happens at random; and it's fixed once I restart the webserver.

That's why I am looking for help or pointers on whether somebody ever experienced that or not. That issue is most definitely not related to version upgrading and migrating to PHP 7 is simply dodging a bullet that, for all I know, may not fix anything since I am not addressing the issue whatsoever.

I understand where you are coming from but that is simply no solution to the current problem.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 720
Joined: Mon Feb 22, 2016 5:52 pm

Wed Feb 07, 2018 4:14 pm

I understand your frustration, but I can only give general advice since your description is very general.

While it may possible that you have found a bug in PHP 5.5, it is still unlikely from your description. The error is more likely in your scripts - the possibilities from there are that you have got away without noticing errors when using 5.3, or changes in 5.5 have introduced some issues. Either way, errors (mostly) are not random they are the result of a coding / logic error, could you show the exact fatal error message that you are getting.

JuanMdP
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Feb 06, 2018 9:08 am

Wed Feb 07, 2018 4:49 pm

I think that given the cryptic issue I'm having I've been pretty clear, the error is specific: Fatal error: Class '<classname>' not found in <include file calling a bunch of classes> on line <line number>. That is all I have to work with and as I've explained several times now, it's not a matter of errors in transition from one version to the other. PHP itself is telling me it can't find a class, not that it's having some issue with something I'm doing. The OP mentions how when it happens, if I include the file outside of the main file calling all the classes then the class will be loaded without issues. If the class would have an error it would fail no matter what 24/7 as opposed to once every several days.

The fact the issue is resolved by restarting IIS is quite telling, it's not a matter of an error in a script. I also never even considered nor implied this is a bug in PHP, it's very likely this is an IIS issue, why else would things go back to normal if you restart the webserver? Why would a class file that was being loaded just fine until 30 secs ago no longer be found? But since in the official IIS forums people are having a hard time understanding this is not related to PHP configuration I figured I'd ask on PHP forums in case somebody ever had similar awful experiences between PHP and IIS.

Post Reply