-1

Im a seasoned dev that just wants to know if PHP is capable of setting variables at certain times of the day. For instance, I have a video of the day widget which I can manage on my own by changing the WHERE id='$x', but I'd like $x to $x to be randomized like executing ORDER BY rand() LIMIT 1. The issue with ORDER BY rand() LIMIT is that it changes every page load when I'd just want the '$x' from WHERE id='$x' to be changed at midnight every day.

So does PHP allow time-based executions, or is that considered a cron job? Please note I have no idea im just guessing terms.

4

3 回答 3

1

PHP是客户端执行的服务器端脚本。如果您希望它在正常浏览之外执行特定操作,则需要设置 ap cron 作业。

于 2013-11-14T08:33:46.973 回答
0

如果您正在计算“当天视频”链接以响应客户请求,我会说去rand()调用确定$x,但使用仅取决于日期的值为数字生成器播种:

<?php
srand(date('Ymd'));
$videoId = rand(0, 100);// change to whatever your maximum video id is

不需要额外的 cron 作业,也不需要存储值或修改脚本。

于 2013-11-14T08:47:22.240 回答
0

嗨,亲爱的,您可以使用 php 服务器功能 'CRON JOB' 此功能抛出您可以设置 PHP 脚本的执行时间并更新您的 Web 或应用程序。

所以首先 crate php 脚本并设置 SERVER 文件链接并设置为时间。

您可以阅读此链接并在服务器上设置文件链接。

http://www.thesitewizard.com/general/set-cron-job.shtml

于 2013-11-14T08:47:45.557 回答