start a function after X minutes on a php page

Asked

Viewed 51 times

-3

For example :

I have a page that performs a function after 7 minutes on it.

This function will increase "+1" in a field of my database.

  • it was not clear, you already have the code of what you want to do ? you could explain your question better ? apparently looking for the Sleep function()

  • 2

    There are many answers on the site about this, each using a approach different. It would be the case that you [Edit] the posting being more specific in relation to the environment that this will run. Depending on the case, the path can be linux cron or windows task scheduler. Depending on the case, it may be the case of a JS on your page, depending on the case it may be another solution that does not pass near those mentioned. Rarely will a pure PHP solution be suitable (unless it is a local executable doing an extensive task, which does not apply to "one page" as mentioned)

1 answer

-2


It’s called asynchronous processing. There are several ways to do this, the first:

<?php

// Seu codigo aqui...

// Aqui chama o script que será executado em 7 minutos
exec("php executarApos7Min.php");

// ...

Code of executarApos7Min.php

<?php
ignore_user_abort(true);
set_time_limit(0);

//Pausa
sleep(420);

// sua query que soma +1

Another way:

$socketCon = fsockopen($host, 80, $errno, $errstr, 10);
if($socketCon) {   
   $socketDados = "GET www.meuserver.com.br/executarApos7Min.php HTTP 1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n";      
   fwrite($socketCon, $socketDados); 
   fclose($socketConexao);
}
  • Hello, João. Welcome to [en.so]! Your question probably received negative votes because it lacked some context on the approaches mentioned in it and also because the question is not clear, soon it becomes very difficult for those reading this question to determine if the codes really solve any problem and in which cases they are useful and can be applied. My suggestion to avoid getting negatives in the future is to make sure first that the question is clear and that you are answering it objectively, if possible giving some context about your solution.

  • Users of the site generally vote conforms to the quality of the question and answer. If you have questions, you can start reading about how to answer. Hug!

Browser other questions tagged

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