开发者

Run program in background, constantly, on a web server - preferably in PHP

开发者 https://www.devze.com 2023-01-24 18:59 出处:网络
I want to create a website application, that will allow our members to get text message/email alerts every day 1 hour before their lesson (a reminder).

I want to create a website application, that will allow our members to get text message/email alerts every day 1 hour before their lesson (a reminder).

My server-side language background is strictly in PHP (although I've tampered some c++ back in the day). For this to work, obviously, I'll needs to somehow run a program constantly on my server.

Can this be accomplished in PHP? If yes, is php efficient at this? If not, how can I do thi开发者_运维百科s?

Or, maybe, this an entirely wrong approach, and there's a better way of creating such a service.


yes, u can consider make PHP as a daemon

or check this out php execute a background process

or simply use cron - http://en.wikipedia.org/wiki/Cron

but you should NOT create a web service/application just to run background PHP processes, it should cater for complex job


Sure, you can use PHP as a scripting language on the server. It's just as capable as any other.

Write a PHP script that checks your database for what members need to be alerted, then sends the message. Add a crontab to run this script every minute/hour/whatever. To run a php script from the command line, you run the php interpreter and give it the script name to run.

$ php /path/to/script.php


You would have to start a service on the server itself or create a CRON job to run at any given interval. If you don't have admin privileges you will have to do a CRON job, which can usually be setup in your host's cpanel.

For instance, you could create a small PHP script that

1) Searched for all lessons that start in the hour proceeding the current hour. So if the script is run at 5pm it would search for lessons that start between 6pm and 6:59.

2) Send an email to those members.

It wouldn't be exactly 1 hour though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号