13
2009
Search in Files using PHP Script with unix commands
Search in large number files is painful & slow for the Magento based projects.
If you are using your editor’s built-in search feature, then also it may take lots of time to search within all directories. In case of you are editing the files on the live server, its very awful to search in even small no. of files for code.
However, there is a solution, if your Magento store is hosted on Linux server. You can get advantages of unix commands.
I made a PHP script which can search in the directory. You can set the directory path in which you want to perform the search.
The example script below can search in ‘app’ directory of your Magento setup. Put the script in the root directory.
<?php
ini_set('max_execution_time', 3600);
ini_set("memory_limit","256M");
$item = $_GET['item'];
if(trim($item) != '')
{
$script = "grep -n -r '$item' ".dirname(__FILE__)."/app";
// replace 'exe c' with 'exec' in this line
$results = exe c($script,$retval);
if($results) {
echo "Search Done";
foreach ($retval as $value) {
echo "".$value;
}
}
else {
echo "Search Done, No results found.\n";
}
}
else {
echo "No Search performed";
}
?>
Name it search.php, then you will need to execute the script from browser this way: http(s)://{host}/search.php?item={keyword}
Related Posts
-
http://www.ferommok.com/ Dirnov
-
http://allzoom.ru.ru Zashkaser
-
http://allzoom.ru Sdanektir
-
http://vmuz.ru Vivalkakira
-
http://jignesht.blogspot.com Jignesh Thummar
-
admin

An article by