Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:06:07+00:00 2026-06-04T07:06:07+00:00

I’m debugging a codeigniter app that intermittently crashes (500 error) when showing a list

  • 0

I’m debugging a codeigniter app that intermittently crashes (500 error) when showing a list of blog posts.

The crash happens 20-30% of page reloads – and seems to be related to either a memory issue of server misconfiguration.

First I went down the controller by doing print_r($array); exit; just below each array that is sent to the view page. No problems if you simply output the array (without passing through view) — there is never a timeout.

So I don’t think the query logic is faulty. Also CI’s profiler shows query times <.001 when the page loads correctly (when it crashes I get 500 error and cannot read the profiler’s info).

Next I moved on to print_r the view’s HTML which has loops for the arrays sent by controller. And that is where there’s a bottleneck that occasionally will cause the 500 error.

The app is designed in such a way that a single view handles all of the arrays sent by the controller and builds an HTML page with the final output.

Because of this, the view has a lot of PHP logic. Several array splits to insert ad units before running foreach loops, conditionals testing for post parameters, nested foreach loops and such.

It is pretty complex but perfectly readable. However I wonder if it’s too much logic, and if the load of this logic should be separated into smaller fragments (multiple views) and then merged together into a final HTML string.

The view has

  • 30-50 if / elseif, some nested
  • 6-7 foreach, some nested
  • 5 array_splice numerous empty and isset

What’s your take on this issue? Do you typically avoid logic heavy views? Any advice?

Please note I’m not asking about “cleaning” views for the sake of webdesigners etc as in other SO discussions. My point here is if this structure could be causing my timeouts and what would be the potential solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:06:08+00:00Added an answer on June 4, 2026 at 7:06 am

    Firstly, it’s not a question of how readable the template code is – there’s a strong correlation between complexity and the presence of bugs. Cyclomatic complexity is one way to measure complexity; from what you’ve posted, this template has a cyclomatic complexity of at least 60. In all our projects, I aim for a cyclomatic complexity of < 8, and get panicky when we get to 12.

    I wouldn’t be surprised if your view code contains a bug – not just a time-out thing, but some bizarre route through the logic tree that you can’t quite picture by looking at the code.

    The Williams template library gives you several tools to do this – for instance, you can define alternate views to deal with the “if question, render like this, if post render like that” logic. You can also use regions to your benefit here.

    There’s an assumption that because views deal with the user interface, they are less important – but that’s simply not true.

    So, let’s assume you refactor your view into a simpler structure. Will this affect processor load? Well – uh – depends.

    Usually, “maintainability” and “performance” have to be traded off against eachother. The classic example is assembler code versus interpreted languages – for most people, assembler is hard to maintain, whereas interpreted scripting languages are far more tractable; on the other hand, there’s no doubt which is faster.

    In your case, I think the total amount of code will increase – “extract method” as a refactoring, for instance, would increase the amount of code by a few lines – but it should be easier to cache. It should also be easier to identify exactly where the bug occurs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.