Reply to Re: [PHP] Getting queries from files FYI

Your name:

Reply:


Posted by Robin Vickery on 08/25/05 13:00

On 8/23/05, Jay Blanchard <jay.blanchard@niicommunications.com> wrote:
> You may (or may not) remember me posting to the list a couple of weeks
> ago asking about using REGEX to get queries out of PHP files for a
> migration project. I had to let it go for several days, but started
> working on it again yesterday, here is the code (no REGEX was used in
> the making of this code);

Just a thought - and I know it's a little late, sorry.

Have you considered writing a wrapper for mysql_query() that logs its
parameters?

You could:

1. do a search and replace on your code replacing 'mysql_query' with
'mysql_query_wrapper'.

2. put a function definition for mysql_query_wrapper() in an auto_prepend file.

function mysql_query_wrapper()
{
$args = func_get_args();
$backtrace = debug_backtrace();
$details = $backtrace[0];
log(sprintf("%s (line %d): %s\n", $details['file'],
$details['line'], $details['args'][0]));
return call_user_func_array('mysql_query', $args);
}

3. Let your users hammer it for a week or so. Your log should then
contain all the queries used by the app on a day-to-day basis and
where they were called from.

5. Do a grep for all lines containing 'mysql_query_wrapper' and diff
it with your log file. That should give you the locations of the
(hopefully few) remaining queries.

cut -d ':' -f 1,2 logfile.txt | sort --unique > recorded_queries.txt

fgrep -n 'mysql_query_wrapper' /path/*.php | cut -d ':' -f 1,2 | sort
--unique > all_queries.txt

comm -3 recorded_queries.txt all_queries.txt

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация