Welcome Guest, Not a member yet? Register   Sign In
Fatal Error. Uncaught error: Class 'CI_Controller' not found
#1

So this is a kinda old project running CI3 and we're facing this issue. It's very sporadic, it seems like it happens when requesting Ajax routes and the temporary fix testers have found is to "Clear the browser's cache".
From what I can see, people that faced this exact error and reported on StackOverflow have so many different causes too far and between, so I couldn't pinpoint the exact issue.
Of course we don't touch core files, just extend from them in our own controllers, and the fact that it happens at random doesn't help to the issue.

This is a screenshot of what we see in one of the Ajax responses:

[Image: 552b72ef-b77f-4917-8c76-2272b6c7a095]
This stack trace points to this file called MY_Exceptions.php which has this code, reading another issue report here I kinda thought it was because at this point in the lifecycle CI_Controller wasn't loaded, but this is an Ajax call though, wouldn't the Core components be up even before my code is executed at that point?:

[Image: 08e528c6-2986-4f25-97d6-5f65f96acd50]

Again, let me emphasize that this doesn't happen all the time with all the existing Ajax requests, nor consistently through all the user machines and browsers, it just happens, a browse cache clear and it's working as intended again.

What you read previously is the original post on Stack Overflow and Github repo, but I did some further testing:
I tried something, which was removing the file MY_Exception, thinking it wasn't being really used/referenced anywhere and it was just being loaded as a result of a line batch loading the files of a folder in codeigniter, also, that it seemed to be made by one of the previous developers of this project.
Turns out it's absolutely needed, any Exception thrown in the project goes through this file, so everything was breaking in it's absence.
Now, that got me thinking, this CI error is happening on the development environment after any exception is thrown out? maybe? that would've been worrysome because that would compromise the entire try - catch structure we have in the code, fortunatelly it wasn't the case, I forced a condition to throw an Exception and it worked just fine.
But that puts us to the beginning, the only thing we know is that this is a random thing we can't catch just yet, I'll even say more, our tester said last week he got the CI error in another random place, but a couple hours later when I told him to check something for me, he went to test it again and it wasn't happening anymore, he didn't even need to clear cache.
Can you people help me try to find the cause of this issue? thanks in advance
Reply
#2

To troubleshoot this sporadic issue with CodeIgniter 3 (CI3) and Ajax requests, consider the following steps:
  1. Error Logging: Enable detailed error logging in CodeIgniter to capture more information about when and how the issue occurs. Check the application/config/config.php file and set log_threshold to a higher level (e.g., 4 for all messages).
  2. Browser Cache: Since clearing the browser cache resolves the issue temporarily, investigate whether any caching headers are incorrectly set in your Ajax responses. You might need to adjust caching settings or headers.
  3. Session Handling: Check if the issue is related to session handling. Ensure that sessions are being managed correctly and consistently across different Ajax requests.
  4. Concurrency Issues: Consider race conditions or concurrency issues, especially if multiple Ajax requests are hitting the server simultaneously. Use logging to track requests and responses for patterns.
  5. Database Connections: Verify that all database connections are correctly closed after use and that there are no lingering connections causing sporadic behavior.
  6. Server-Side Caching: Look into any server-side caching mechanisms that might be causing stale data to be served to Ajax requests.
  7. Review Custom Code: Since MY_Exceptions.php is custom, review its logic to ensure it’s not inadvertently interfering with Ajax request handling or error reporting.
  8. Environment Consistency: Ensure that development, testing, and production environments are consistent in terms of server configurations and software versions.
By following these steps, you should be able to gather more information about the issue and identify potential causes.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB