Perform task scheduling via PHP in windows

Asked

Viewed 658 times

1

I need to schedule the sending of 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 him via command line: php -f addressFile it works perfectly. Already when I call it by browser the script just doesn’t work.

If anyone knows what it can be I’m very grateful.

The result of var_dump() and 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 "
  • When you use the browser, what is the result of the command var_dump()? Edit your question and enter these values please.

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

2

A script simpler 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 indicate that you should configure the IIS.

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

I wouldn’t do that, this could be a security breach. I would let it run by the server in a protected way. That is, if you need privileged access, do not let 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);

  • The question is that who knows when the email has want to be send and apply this after a given user action. So who schedule task could be schedule for any time at any time whatever application is running. I do not see how the task should be scheduled by someone other than an application (even if it is a security breach), and of course I do not need to use the function system, for example hj scheduling works through a daemon application, which I imagine is more secure because not external access to the system but less reliable.

  • Look, your text is a little strange, I don’t know if I understand. But I’ll tell you what, no requirement is worth opening the server security.

  • I’m sorry I’m not very good at writing. The question is that today it works with a daemon application in php and communication and done with real application through a file. The other possibility is SCHTASKS through which I could not make it work probably because of the permission issue and it was my first idea. Only how I couldn’t make it work post the question to see what I’m doing wrong so it doesn’t work.

  • Here just one question what would you do in this issue would keep the application of the daemon or would you find another solution? Here already thank you very much for your reply she has already helped me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.