简体   繁体   English

使用PHP + MySQL的服务器进程

[英]Server process with PHP+MySQL

I am new to web programming, and I am developing a simple appointment app with PHP + MySQL. 我是Web编程的新手,并且正在使用PHP + MySQL开发一个简单的约会应用程序。 Is there a simple way to add a background process on a timer (to send out daily appointment reminders, for example)? 是否有一种简单的方法可以在计时器上添加后台进程(例如,发送每日约会提醒)? This could be done easily in another language, but I want it to run on shared hosting with only PHP. 可以使用另一种语言轻松完成此操作,但是我希望它仅在PHP上运行在共享主机上。

Your host may or may not approve of this. 您的房东可能同意也可能不同意。 You can write a PHP script for use on the command line and make a crontab entry to run it periodically. 您可以编写一个PHP脚本以在命令行上使用,并创建一个crontab条目以定期运行它。 If you don't have command-line access to the PHP interpreter, you could write the script to run in the web server and hit it with wget or curl, also using a crontab entry. 如果您没有命令行访问PHP解释器的权限,则可以编写脚本以在Web服务器中运行,并使用crontab条目使用wget或curl使其命中。

If you have a Linux webhost, you might be able to use a cronjob (to automatically run a script periodically)--even on shared hosting. 如果您拥有Linux虚拟主机,则即使在共享主机上,也可以使用cronjob(定期自动运行脚本)。 Some webhosts with shared web hosting allow you to create cronjobs via cPanel (or whatever they use). 一些具有共享虚拟主机的虚拟主机允许您通过cPanel(或它们使用的任何东西)创建cronjob。

That would really be your best bet, as opposed to creating a background process on the server, which the webhost probably would not be very kind about. 与在服务器上创建后台进程相反,这确实是您最好的选择,Web主机可能对此不太好。 So definitely check and see if you can use cron. 因此,请务必检查并确定是否可以使用cron。

I work in a place where I cannot set a cron job so I made a page that when viewed it checks the time since the last time it did a list of jobs. 我在无法设置Cron作业的地方工作,因此我创建了一个页面,该页面在查看时会检查自上次执行作业列表以来的时间。 If the time since job last run is over a set threshold it runs the list of jobs. 如果自作业上次运行以来的时间超过设置的阈值,它将运行作业列表。 Then I set up a scheduled job on a computer that I know is on all the time and connected to the internet and would open the page every 10 minutes. 然后,我在一直知道并一直连接到Internet的计算机上设置了计划的作业,并且每10分钟打开一次页面。 Worked pretty constantly. 不断地工作。 Got the idea from Joel on a stack overflow podcast episode. 在堆栈溢出播客中从乔尔那里得到了这个主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM