私はphpでExcelファイルの内容に基づいて動的cronジョブをスケジュールし、それらの値をスクリプトに渡していますargv
。私のコードは次のとおりです。
$data = new SpreadSheet_Excel_Reader("sample-data.xls", false);
$surveyToken = "Token";
$email = rawurlencode($data->val(2, "B"));
$dateCompleted = rawurlencode($data->val(2, "C"));
$followUpOne = rawurlencode($data->val(2, "E"));
$followUpTwo = rawurlencode($data->val(2, "F"));
$programName = rawurlencode($data->val(2, "G"));
$subject = rawurlencode($data->val(2, "H"));
$firstName = rawurlencode($data->val(2, "I"));
$lastName = rawurlencode($data->val(2, "J"));
$learningGoal = rawurlencode($data->val(2, "K"));
$importanceScore = rawurlencode($data->val(2, "L"));
$confidenceScore = rawurlencode($data->val(2, "M"));
$strategies = rawurlencode($data->val(2, "N"));
$timeLine = rawurlencode($data->val(2, "O"));
$measures = rawurlencode($data->val(2, "P"));
$resources = rawurlencode($data->val(2, "Q"));
$output = shell_exec("crontab -l");
file_put_contents("crontab.txt", $output . "39 * * * * /usr/local/php53/bin/php mail.php $surveyToken $email $dateCompleted $followUpOne $followUpTwo $programName $subject $firstName $lastName $learningGoal $importanceScore $confidenceScore $strategies $timeLine $measures $resources" . PHP_EOL);
exec("crontab crontab.txt");
私は、mail.php スクリプトで生の URL デコードを使用し、から変数を取得してそのメールを送信していますargv
。
出力された「url」とその引数を使用してコマンドラインで実行するだけで、このスクリプトをテストしました。cron ジョブをスケジュールするのではありません。
そのように実行すると、正常に動作します。上記のコードを実行すると、cron ジョブは正常に機能し、php ファイルは引き続きメールを送信しますが、すべての変数はargv
.