api creating task files
This commit is contained in:
parent
de681f37b0
commit
91d85232ca
2
api.php
2
api.php
|
@ -69,9 +69,9 @@ if(!is_dir($taskDir)){
|
||||||
$taskfilename = $taskDir.'/'.time().'-'.bin2hex(random_bytes(4)).'.txt';
|
$taskfilename = $taskDir.'/'.time().'-'.bin2hex(random_bytes(4)).'.txt';
|
||||||
$taskfile = fopen($taskfilename, 'w');
|
$taskfile = fopen($taskfilename, 'w');
|
||||||
if($taskfile){
|
if($taskfile){
|
||||||
echo "Task written to file";
|
|
||||||
fwrite($taskfile, $taskString);
|
fwrite($taskfile, $taskString);
|
||||||
fclose($taskfile);
|
fclose($taskfile);
|
||||||
|
echo "Task written to file";
|
||||||
} else {
|
} else {
|
||||||
echo "Task not written to file";
|
echo "Task not written to file";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,48 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$maxExecutionTime =
|
||||||
|
$taskDir = 'tasks';
|
||||||
|
phpinfo();
|
||||||
|
function doRequest($task)
|
||||||
|
{
|
||||||
|
echo "doing Request: ".json_encode($task);
|
||||||
|
}
|
||||||
|
|
||||||
>
|
function sendEmail($emailAddress, $filename)
|
||||||
|
{
|
||||||
|
echo "sending ".$filename." too ".$emailAddress;
|
||||||
|
}
|
||||||
|
if(is_dir($taskDir)) {
|
||||||
|
$taskfiles = scandir($taskDir);
|
||||||
|
$taskfiles = array_diff($taskfiles, array('.', '..'));
|
||||||
|
sort($taskfiles);
|
||||||
|
if(count($taskfiles) > 0) {
|
||||||
|
$taskString = file_get_contents($taskDir.'/'.$taskfiles[0]);
|
||||||
|
$task = json_decode($taskString, true);
|
||||||
|
|
||||||
|
// if there are any requests to do, do the first
|
||||||
|
if(count($task['requests']) > 0) {
|
||||||
|
doRequest($task['requests'][0]);
|
||||||
|
echo "Request done";
|
||||||
|
array_shift($task['requests']);
|
||||||
|
$taskString = json_encode($task);
|
||||||
|
$taskfile = fopen($taskDir.'/'.$taskfiles[0], 'w');
|
||||||
|
if($taskfile){
|
||||||
|
fwrite($taskfile, $taskString);
|
||||||
|
fclose($taskfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if there are no Requests left, send the E-Mail
|
||||||
|
else {
|
||||||
|
sendEmail($task['email'], $taskDir.'/'.$taskfiles[0]);
|
||||||
|
echo "Email sent";
|
||||||
|
unlink($taskDir.'/'.$taskfiles[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Task dir Empty";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "no Task dir";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue