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

  • SEARCH
  • Home
  • 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 8844929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:36:39+00:00 2026-06-14T11:36:39+00:00

I am working on a very large PHP codebase (mostly procedural) which has been

  • 0

I am working on a very large PHP codebase (mostly procedural) which has been pieced together over the past 10 years by developers who came before me and we are now experiencing heavy database load. A peek into some files show upwards of 40 to 60 MySQL queries being executed. Spending the time to trace out what they are used for in this large obnoxious files often shows they query was made and the results were never used. I feel if I can identify the problem areas in the codebase, I can start to refactor.

I’ve seen many posts on StackOverflow about various auditing tools:

  • https://stackoverflow.com/questions/4273244/auditing-a-php-codebase?lq=1
  • Is there a static code analyzer [like Lint] for PHP files?

I have yet to find anything that analyzes query usage in a script though. For example, how many SELECT, INSERT, and UPDATE queries are contained in the file. And more interestingly, how many of those are contained inside of a looping structure? I wrote a quick a dirty recursive file search to identify some of the basic issues:

   $it = new RecursiveDirectoryIterator($path);
   foreach(new RecursiveIteratorIterator($it) as $file) 
   {
      if(stristr($file, "/.") == false && stristr($file, "/..") == false)
  {
         $contents = file_get_contents($file);

         // Regular MySQL queries...indicative of SQL injection points
         $mysql_count = substr_count($contents, "mysql_query(");

         $select_count = substr_count($contents, 'SELECT ');
         $insert_count = substr_count($contents, 'INSERT INTO');
         $update_count = substr_count($contents, 'UPDATE ');

         if($mysql_count > 0 || $select_count > 0 || $insert_count > 0 || $update_count > 0)
         {
            $out[] = array('file' => $file, 
                           'mysql_count' => $mysql_count,
                           'select_count' => $select_count,
                           'insert_count' => $insert_count,
                           'update_count' => $update_count
                          );
         }

         $contents = null;
    }
}

var_dump($out);

But that doesn’t find anything in loops, or even analyze the query to see if maybe it contains a high threshold of JOINS. I can write a tool like this, but why reinvent the wheel if it already exists?


Are there any tools to identify PHP files which may potentially have problematic/high stress/inefficient queries?

My goal is to identify points where refactoring of legacy procedural code will be most beneficial.

  • 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-14T11:36:40+00:00Added an answer on June 14, 2026 at 11:36 am

    Worse than lots of queries are slow queries. So I would try to find those.

    You could do that using the slow query log feature of MySql:
    http://dev.mysql.com/doc/refman/5.6/en/slow-query-log.html

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

Sidebar

Related Questions

I'm working on a very large project that has associated class files in multiple
We're working with some very large config files which contain lots of Unity and
I'm working on a project which generates a very large number of sequential text
I am currently working on a very specialized PHP framework, which might have to
I am working on a very large project that has several Visual Studio projects.
I'm working on a fairly large project in (object oriented) PHP which includes a
When working with very large documents, would it basically overwhelm the connection and ground
I'm working on a very large project with three phases of source code. Development
I'm working on a very large query, in a inherited application. This is a
I've recently begun working on a very large, high traffic website. We would very

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.