I think this has to be a very simple question but I am not finding any answers for what I am trying to accomplish.
I have a PHP file which will send out emails. This part works. The thing is, I need this PHP file to “run” every 5 minutes.
My problem is not with the scheduling, I’m fairly certain I understand how to do that.
My issue is with the “running” of the PHP file.
My mind is totally void of any information of how to “execute” a PHP file rather than just make it open in a browser and spit its code everywhere.
I know that this PHP file works because when I am working on it in Dreamweaver and I click the “Discover” link where it says “Dynamically-related files for this document may have changed and should be re-discovered by the server” it executes this PHP file and I get my emails sent.
I’ve tried going through command line like THIS but all it does is spit out the php code as if I was running it in a browser. Nothing actually sends.
Is there some way to change the way the PHP file itself is formatted that would make it do this?
What is Dreamweaver doing when I click “Discover” that makes it work?
I feel like this should be a simple thing and its insane that I am not understanding it…..
You have options. If it’s a web page that you can access through your browser (and that sends the email as you’d expect), you can just request that page via HTTP every five minutes. Personally, I’d do this with cURL (e.g.,
curl.exe http://localhost/myfile.php). You can find Windows binaries here. You could also use PowerShell or something.If this isn’t a web page, or if you just don’t feel like going that route, you can execute the PHP through PHP’s command-line interface (CLI), as you’ve already figured out.
C:\path\to\php.exe myfile.phpwill execute your code and spit the output to STDOUT. If everything is working with this except for sending email—which I’m guessing you’re doing throughmail—the issue may be with your PHP configuration. By default, PHP looks for the php.ini file in these locations. You can also explicitly tell the PHP CLI what php.ini file to use with the-coption (e.g.,php.exe -c C:\path\to\php.ini myfile.php). Of course, you’ll need to have everything configured properly in php.ini to send mail. This can be a bit trickier on Windows than on your average Linux machine withsendmailavailable.