2011-01-07 7 views
1

PHP에서 하나의 exmaple을 마친 후 스크립트를 실행하는 가장 좋은 방법은이 두 파일이 있습니다.아마존 S3 백업

내 백업 파일.

<?php 
require 'back-up.php'; 

#!/bin/php -d max_execution_time = 3600 

$backup_dirs = array('../bu/'); 
$backup = new backupclass($backup_dirs); 
$backup->backup('filesys','files/'); 
?> 

내가 내 아마존 S3 업로드 파일이 있습니다. 좋아

<?php 

require_once('S3.php'); 

$s3 = new S3('S3KEY', 'S3SECRETKEY'); 

$baseurl = "/home/mlcreative/public_html/bu/files"; 

if ($handle = opendir('./files/')) { 
    while (false !== ($file = readdir($handle))) { 
     if ($file != "." && $file != "..") { 

      if ($s3->putObjectFile("files/$file", "testingmlc333", "lighthouse/$file", S3::ACL_PUBLIC_READ)) { 

        echo "<strong>We successfully uploaded your file.</strong>"; 
        if (file_exists($baseurl . '/' . $file)) { unlink ($baseurl . '/' . $file); } 
}else{ 
        echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; 
} 

     } 
    } 
    closedir($handle); 
} 

?> 

그래서 그 순간에 내가 다음 시간 후에 아마존 업로드 PHP 파일을 실행 백업 PHP 파일을 실행하는 cron 작업 설정이 있습니다.

내가 묻는 것은 두 가지 대신 하나의 cron 작업 만 실행하도록 스크립트에 결합 할 수있는 방법입니다. ???

어떤 도움을 주시기 바랍니다

답변

1

당신은 백업이 완료되면 (# 1) 스크립트 URL을 통해 업로드 (# 2) 스크립트를 호출을 만들 수 있습니다.

# Script Number 1 - Backup 
/* After all the content */ 
@file_get_contents('http://www.yourserver.com/uploadToS3.php?protector=somethingSecret'); 

# Script Number 2 - Uploader (available at the URL above) 
/* Before all the content */ 
if($_GET['protector']!='somethingSecret'){ 
    die('Access Blocked'); 
} 

즉, 백업 스크립트가 완료되면 업로드 스크립트가 트리거됩니다. protector=somethingSecret은 실수로 트리거되지 않도록하기위한 것입니다.

0

첫 번째 스크립트 다음에 두 번째 스크립트를 실행하도록 cron 작업을 수정하십시오. 내가 cronjobs의 많은이 방법을 사용

php -f firstscript.php ; php -f secondscript.php 

다음 cronjob를의 명령 필드에서와 마찬가지로 다음과 같이 보일 것입니다.

관련 문제