Perform task scheduling via PHP on windows

1

I need to perform the scheduling of sending an email dynamically on a windows server running IIS. I have the following code in PHP:

    class AgendarTarefaWindow{

       public function agendar($nome, $data, $tarefa){
           $array = explode(' ',$data);

           $comando = 'SCHTASKS /Create /SC ONCE /TN '.$nome.' /TR "'.$tarefa.'" /ST '.$array[1].' /SD '.$array[0].' /F ';

           $dados = system($comando,$resultado);

           var_dump($dados, $resultado, $comando);
        }

        public function excluirAgendamento($tarefa){
           exec('schtasks /Delete /TN '.$tarefa.' /F');
        }
    }  

    $agenda = new AgendarTarefaWindow();  

    $agenda->agendar('ncccTeste', date('d/m/Y H:i:s',strtotime( "+2 minute",strtotime(date('Y-m-d H:i:s')))), 'php -f  C:\inetpub\wwwroot\ClickFood\obj.php');

If I call it via the command line: php -f enderecoFile it works perfectly. When I call it through the browser, the script simply does not work.

If anyone knows what it can be I am very grateful.

The result of var_dump () is the following:

   string(0) "" 
   int(-2147467259) 
   string(121) "SCHTASKS /Create /SC ONCE /TN ncccTeste /TR "php -f C:\inetpub\wwwroot\ClickFood\obj.php" /ST 14:30:00 /SD 23/07/2015 /F "
    
asked by anonymous 28.07.2015 / 02:51

1 answer

2

Does a simpler script run? If nothing in PHP runs, IIS is not configured to run PHP. And then, since the question does not give details, I can only make this diagnosis and tell you that you should configure IIS .

If only this script is not working, it could be a privilege problem. Give permission to access the script in a privileged way in which all the secondary scripts called there can be executed.

I would not do this, this can be a security breach. I would let it be run by the server in a protected way. That is, if you need privileged access, do not let the access be done externally. If you need external access, do not do anything privileged.

This line is the paradise of hackers : $dados = system($comando,$resultado);

    
28.07.2015 / 03:09