简体   繁体   English

如何每月自动运行一个PHP脚本

[英]How to run a PHP script automatically in every month

I have the php project for user can register and buy the hours to listen music or video, the not used of 50% hours have to rollover to next month, I wanted to automate this process when user complete one month I have to check their usage and process the rollover using php. 我有一个php项目,用户可以注册并购买可以收听音乐或视频的时间,未使用的50%的时间必须转换到下个月,我想在用户完成一个月后自动执行此过程,我必须检查其使用情况并使用php处理过渡。 I have following user details on DB, Signed-up date with time and usage and hours they purchased and used hours. 我有以下关于DB的用户详细信息,注册日期,时间和使用情况以及他们购买和使用的小时数。 I want to do it once in a month for each customer. 我想每个月为每个客户做一次。

Is it possible using cron jobs? 可以使用cron作业吗? I don't have any idea to do this. 我不知道要这样做。

Not sure if this is the right approach but I've been running such kind of scripts when a user logs into his account. 不知道这是否是正确的方法,但是当用户登录其帐户时,我一直在运行此类脚本。

For example. 例如。

You can do something like on successful login request by the user 您可以对用户成功登录请求执行类似操作

if(date of buying hours has crossed the specified limit) /here you can check for expiry date/
{ // run your script here
     }
else{}

just a suggestion! 只是一个建议!

You don't need to update all of the records all at once. 您不需要一次更新所有记录。 Just update it for the user who logs in. At the end, it will be updated for every user I think. 只需为登录的用户更新它即可。最后,我认为的每个用户都将更新它。

Short answer : Use Cron job. 简短答案 :使用Cron作业。

Syntax and usage of how to use it is almost straight forward. 语法和用法的用法几乎是直接的。 Here's a cheat sheet . 这是备忘单

Note: If you're on a shared host, some hosts don't allow you to use cron job. 注意:如果您在共享主机上,则某些主机不允许您使用cron作业。

Edit: What @Havenard suggested is correct. 编辑: @Havenard建议的是正确的。 The below cron job will visit the url once at minute 00 of every hour: 以下cron作业将在每小时的00分钟访问一次该网址:

0 * * * * wget http://www.mywebsite.com/some/link

yes this possible with Cron Job 1st Create your php file with your condition use update query then add this cron job file in your server Cron Job Section and select date when you want to run this file. 是的,Cron Job 1st可以做到这一点。根据条件使用更新查询创建您的php文件,然后将此cron作业文件添加到服务器的Cron Job节中,并选择要运行此文件的日期。 in cron job just file your cronjobfile.php name , Date and time when this file run. 在cron作业中,只需输入您的cronjobfile.php名称,该文件运行的日期和时间即可。

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

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