Çoklu Site Kurulumları için Dönemsel Görevler
enbilulu, Per, 24/12/2009 - 01:22 tarihinde.
Drupal'de dönemsel görevlerin öneminden daha önce bahsettim zaten. Eğer tek bir kod sistemi üzerinde birden çok Drupal sitesi kurduysanız bu sitelerin her biri için ayrı ayrı cron görevi ayarlamanız gerekmez.
Bunun için ilk öncelikle Drupal ana dizininin bulunduğu yere cronall.php gibi bir dosya oluşturun ve aşağıda yer alan kodu içine kopyalayın ve gerekli değişiklikleri yapıp kaydedin. Daha sonra bu dosyayı ziyaret ederek doğru çalışıp çalışmadığını kontrol edin. Eğer her şey düzgün bir şekilde işliyorsa artık önceki sayfada anlatıldığı gibi sadece bu dosya için bir dönemsel görev ayarlayarak bitirebilirsiniz.
<?php
/**
* This script scans the sites directory, and uses a regular expression to extract the sitenames.
* It then uses this sitename to execute the cron job for these sites.
* You then only have to create a cron job for this script.
* In this way, you can create and delete sites on the fly, but all their cron jobs will be executed.
*/
/***********
* SETTINGS
**********/
//the location of the 'sites' directory relative to this script.
$sitesDir = '../drupal/sites';
/**
* A regular expression that matches the name of the directories in
* the 'sites' dir that you want to execute cron jobs for, with a
* backreference around the actual site name. (so we can exclude the
* domain part)
*
* If you don't know regular expressions you might want to brush up
* on them: <a href="http://www.regular-expressions.info/tutorial.html
" title="http://www.regular-expressions.info/tutorial.html
" rel="nofollow">http://www.regular-expressions.info/tutorial.html
</a> *
* Alternatively, you can just copy the name of one of the directories
* in the site dir, put a backslash \ in front of all dots . and replace
* the actual name of the site with ([a-zA-Z0-9_-])
*/
$siteNameRegExp = 'www\.example\.com\.([a-zA-Z0-9_-])';
//the url of the cron script, you should insert %s where the sitename should be inserted later.
$cronUrl = 'http://www.example.com/%s/cron.php';
//any other sites that you want to execute cronjobs for. Just comment this if you haven't got any.
$addedSites = array('drupal');
/***********
* END SETTINGS
**********/
error_reporting(E_ALL);
$sites = array();
$handle = opendir($sitesDir);
while ($file = readdir($handle)) {
if(ereg($siteNameRegExp, $file)){
$sites[] = ereg_replace($siteNameRegExp, '\\1', $file);
}
}
//default site
if(isset($addedSites) && is_array($addedSites)){
$sites = array_merge($sites, $addedSites);
}
foreach($sites as $site){
$cmd = 'wget --spider '.sprintf($cronUrl, $site);
echo 'Executing command: '.$cmd.'<br>';
exec($cmd);
}
?>
/**
* This script scans the sites directory, and uses a regular expression to extract the sitenames.
* It then uses this sitename to execute the cron job for these sites.
* You then only have to create a cron job for this script.
* In this way, you can create and delete sites on the fly, but all their cron jobs will be executed.
*/
/***********
* SETTINGS
**********/
//the location of the 'sites' directory relative to this script.
$sitesDir = '../drupal/sites';
/**
* A regular expression that matches the name of the directories in
* the 'sites' dir that you want to execute cron jobs for, with a
* backreference around the actual site name. (so we can exclude the
* domain part)
*
* If you don't know regular expressions you might want to brush up
* on them: <a href="http://www.regular-expressions.info/tutorial.html
" title="http://www.regular-expressions.info/tutorial.html
" rel="nofollow">http://www.regular-expressions.info/tutorial.html
</a> *
* Alternatively, you can just copy the name of one of the directories
* in the site dir, put a backslash \ in front of all dots . and replace
* the actual name of the site with ([a-zA-Z0-9_-])
*/
$siteNameRegExp = 'www\.example\.com\.([a-zA-Z0-9_-])';
//the url of the cron script, you should insert %s where the sitename should be inserted later.
$cronUrl = 'http://www.example.com/%s/cron.php';
//any other sites that you want to execute cronjobs for. Just comment this if you haven't got any.
$addedSites = array('drupal');
/***********
* END SETTINGS
**********/
error_reporting(E_ALL);
$sites = array();
$handle = opendir($sitesDir);
while ($file = readdir($handle)) {
if(ereg($siteNameRegExp, $file)){
$sites[] = ereg_replace($siteNameRegExp, '\\1', $file);
}
}
//default site
if(isset($addedSites) && is_array($addedSites)){
$sites = array_merge($sites, $addedSites);
}
foreach($sites as $site){
$cmd = 'wget --spider '.sprintf($cronUrl, $site);
echo 'Executing command: '.$cmd.'<br>';
exec($cmd);
}
?>
- Yeni yorum ekle
- 1108 kez okundu
