Sunday, January 17, 2010

drupal cron for multiple sites

There are times when we have multiple site to maintain for our drupal based websites.
One way to do it is by doing a shell script.
But i would prefer to do it using php script instead:

runcron.php
------------------------

$aSites = array(
"http://xyz.com/cron.php",
"http://example.com/cron.php"
);
foreach( $aSites as $sSite ):
$sContent = file_get_contents($sSite);
echo "Retrieved: " . $sSite . "\r\n
";
echo substr($sContent,0, 100) . "...\r\n
";
endforeach;

-------------------
And setup the cron in cpanel:
php [path_to_your_php]/runcron.php
etc.: php /home/example.com/public_html/mydrupal/runcron.php > /dev/null

Hope this is helpful :)

Monday, January 11, 2010

php ereg is deprecated

Since php 5.3, a lot of functions has been deprecated.
One of the issue is oscommerce. These are the suggested replacement for the code:

ereg => preg_match
eregi => preg_match('/[existing]/i'...)
split => preg_split
ereg_replace => preg_replace

example for eregi:
eregi('^[a-z0-9]$', $char)
to
preg_match('/^[a-z0-9]$/i', $char);


hope it helps :)

Saturday, November 14, 2009

Drupal upload path

To get where is the default path to upload file of the site:
file_directory_path()
example return: sites/xyz.com/files

Reference:
http://api.drupal.org/api/group/file/6

Other interesting discussion here:
http://groups.drupal.org/node/13420

Monday, November 9, 2009

drupal admin mysql has gone away!

Its such a hectic day.
I tried to clear the cache and i'm getting bunch of errors from mysql has gone away!
It turn out to be some very long query to update cache_update table and caused it to started to lost connection to db.. arg! I added a static variable to count the # of queries to database,, wow! 250+ queries! the front page itself about 110+queries!....

my here is my quick fix to the problem:
edit: drupal/includes/database.mysql.inc
function: _db_query
line #111, before mysql_query line.
(updated 10th nov: if ping is placed after mysql_query, db_effected_rows will always return -1, which causes lots of other issues)

//****BEGIN ATTEMPT TO RECONNECT ON ERROR
try {
if (! mysql_ping($active_db))
{
throw new Exception("db closed!");
}
}
catch (Exception $e)
{
//attempt to reconnect
global $db_url;
$urlname = "default";
if (is_array($db_url)) {
$connect_url = array_key_exists($urlname, $db_url) ? $db_url[$urlname] : $db_url['default'];
}
else {
$connect_url = $db_url;
}

$active_db = db_connect($connect_url);
}
//****END ATTEMPT TO RECONNECT ON ERROR


And these are my modules i've installed, while some are my custom modules:
/var/www/mydrupal/sites/all/modules/advanced_help
/var/www/mydrupal/sites/all/modules/aes
/var/www/mydrupal/sites/all/modules/apisetting
/var/www/mydrupal/sites/all/modules/apisettinglist
/var/www/mydrupal/sites/all/modules/apiutils
/var/www/mydrupal/sites/all/modules/backup_migrate
/var/www/mydrupal/sites/all/modules/birthdays
/var/www/mydrupal/sites/all/modules/calendar
/var/www/mydrupal/sites/all/modules/captcha
/var/www/mydrupal/sites/all/modules/casetracker
/var/www/mydrupal/sites/all/modules/cck
/var/www/mydrupal/sites/all/modules/computed_field
/var/www/mydrupal/sites/all/modules/content_access
/var/www/mydrupal/sites/all/modules/crm_account
/var/www/mydrupal/sites/all/modules/customcasetracker
/var/www/mydrupal/sites/all/modules/customintranet
/var/www/mydrupal/sites/all/modules/date
/var/www/mydrupal/sites/all/modules/filefield
/var/www/mydrupal/sites/all/modules/flexifilter
/var/www/mydrupal/sites/all/modules/hellomodule
/var/www/mydrupal/sites/all/modules/i18n
/var/www/mydrupal/sites/all/modules/imageapi
/var/www/mydrupal/sites/all/modules/imagecache
/var/www/mydrupal/sites/all/modules/imagefield
/var/www/mydrupal/sites/all/modules/imce
/var/www/mydrupal/sites/all/modules/imce_wysiwyg
/var/www/mydrupal/sites/all/modules/jquery_dataTables
/var/www/mydrupal/sites/all/modules/languageicons
/var/www/mydrupal/sites/all/modules/mail_api
/var/www/mydrupal/sites/all/modules/messaging
/var/www/mydrupal/sites/all/modules/mimedetect
/var/www/mydrupal/sites/all/modules/mimemail
/var/www/mydrupal/sites/all/modules/node_gallery
/var/www/mydrupal/sites/all/modules/node_privacy_byrole
/var/www/mydrupal/sites/all/modules/notifications
/var/www/mydrupal/sites/all/modules/notify
/var/www/mydrupal/sites/all/modules/og
/var/www/mydrupal/sites/all/modules/pear
/var/www/mydrupal/sites/all/modules/print
/var/www/mydrupal/sites/all/modules/rdf
/var/www/mydrupal/sites/all/modules/realname
/var/www/mydrupal/sites/all/modules/schema
/var/www/mydrupal/sites/all/modules/simplemenu
/var/www/mydrupal/sites/all/modules/simplenews
/var/www/mydrupal/sites/all/modules/subscriptions
/var/www/mydrupal/sites/all/modules/swftools
/var/www/mydrupal/sites/all/modules/thickbox
/var/www/mydrupal/sites/all/modules/token
/var/www/mydrupal/sites/all/modules/translation_overview
/var/www/mydrupal/sites/all/modules/transliteration
/var/www/mydrupal/sites/all/modules/ubercart
/var/www/mydrupal/sites/all/modules/video
/var/www/mydrupal/sites/all/modules/views
/var/www/mydrupal/sites/all/modules/views_customfield
/var/www/mydrupal/sites/all/modules/wysiwyg

Tuesday, October 20, 2009

apache web based monitoring

Ever wonder what is happening on your apache web server?
There are times when we found dead processes which doesnt seems to die off.
And it keeps accumulating and somehow reach its peak memory and dies off the server.
And you were spending many days of sleepless night trying to standby to restart the apache webserver every time it reaches its peak

Here is a solution:
Enable apache mod_status:
sudo a2enmod status
edit status.conf, and replace server-status with your secret url
sudo vi /etc/apache2/mods-available/status.conf

location server-status

restart apache:

apachectl restart

access your browser:

http://www.youdomain.com/server-status or yoursecreturl

Sunday, October 18, 2009

drupal custom url / menu permission

Took me some time to figure this out.
If you ever one to have a url which is accessible by anyone,
you may either make a function to return true,
or you may set 'access callback' => '1'...

If it doesn't work, try go to administration > performance > resetting the cache.
The cache is always there, even with cache is off.