Automatic PHP function

Asked

Viewed 646 times

4

I need every day, the system sends shipping orders to the post office. How can I do this automatically, without needing any user to load the page or anything like that?

I would use the same logic of doing something automatically without user interaction (without having to do something, open some page or something like that) in other things, I haven’t found anything like it so far.

You can do this with PHP?

2 answers

4


Tasks cron / Cron job,

How it works:

create a php file that runs the function you need, and when you open it at http it will run what Voce programmed, now just need something automatic to keep opening the file for you, so host and use the resources of the hosting, in your hosting set up cron tasks to run it from both in so much automated time, Windows has the native function but do not remember where, the linux is called cron job I think. Hosting Support will help you to use there, is a configuration in the control panel itself.

1

Use the CRON!

Making it clearer, the CRON It’s like I’m a person who will enter the link you program from time to time.

My tip for you is to use a hosting that is Linux, because most have the CRON. A configuration example to run a script:

Minuto: *
Hora: *
Dia: *
Mês: *
Ano: *

Comando: curl http://www.meusite.com.br/script_a_executar.php

With this command the CRON will execute the script_a_executar.php every 1 minute.

In case you want to program once a day:

Minuto: 0
Hora: 0
Dia: *
Mês: *
Ano: *

Comando: curl http://www.meusite.com.br/script_a_executar.php

Search how to configure CRON, so you’ll know how to set the time you need.

  • I think there is no reason to run a CURL, especially using the domain instead of the IP, searching for a DNS. I think the easiest thing, if Cron is on the same file server, or on the same network, is to set a command like "php -q /local/do/file.php", it’s faster.

  • It depends. If it’s a framework and you have a controller you won’t be able to call app/controller.php

Browser other questions tagged

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