2012-05-04 25 views
1

跑到我有一臺服務器在我的房間裏有一個Core Duo的處理器和基本的互聯網(沒有什麼花哨)PHP腳本從crontab的時間跑了出來,如果其他腳本在同一時間

我運行Ubuntu 11.04和我正在從crontab運行一個php腳本。

0 3 * * * php back_up_to_s3.php 

此腳本大約需要20-30分鐘才能運行。從crontab運行時,它工作正常,但是如果我與運行5-10分鐘的其他腳本同時運行它。

0 3 * * * php back_up_to_s3.php 
0 3 * * * php do_this.php 
0 3 * * * php do_that.php 

它沒有完成。我的猜測是它超時。這裏是back_up_to_s3.php

include('Zend/Service/Amazon/S3.php'); 
include("connect_to_database.php"); 

$my_aws_key = '******'; 
$my_aws_secret_key = '******'; 
Zend_Service_Amazon_S3::setKeys($my_aws_key, $my_aws_secret_key); 
$s3 = new Zend_Service_Amazon_S3(); 


$fileName = exec("date +'%m_%d_%y'") . '.tar'; 

$filePath ="/home/me/temp_db_backups/$fileName"; 

exec("mysqldump -h localhost -u root -ppassword DATABASE_NAME > $filePath"); 

$s3->putObject('myBucket/' . $fileName, file_get_contents($filePath), 
    array(Zend_Service_Amazon_S3::S3_ACL_HEADER => 
      Zend_Service_Amazon_S3::S3_ACL_PRIVATE,    
      Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER => 
      'audio/mpeg' 
));     

unlink($filePath); 

源我知道劇本沒有完成,因爲柏油備份不會在我的S3存儲桶出現。但是tar文件被創建並且仍然在我的/home/me/temp_db_backups中,所以我知道該腳本在$s3-putObject執行時終止。

+0

可能嘗試增加php.ini中的max_execution_time(可能是/etc/php.ini)。 –

+0

這不會幫助,因爲cli max_execution時間被硬編碼爲0 – user784637

回答

1

你好齊柏林飛船(懷疑我是否會得到每說:)
而不是猜測什麼可能會發生的,輸出重定向到一個日誌文件,你就會知道肯定

 
0 3 * * * php back_up_to_s3.php >/tmp/backup_cronoutput 2>&1 
0 3 * * * php do_this.php >/tmp/do_this_cronoutput 2>&1 
0 3 * * * php do_that.php >/tmp/do_that_cronoutput 2>&1 
+0

感謝kevin,我遵循了您的建議並將錯誤消息追溯到其他人遇到的常見問題。 – user784637