久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在特定時間執行的 PHP 腳本

PHP script to execute at certain times(在特定時間執行的 PHP 腳本)
本文介紹了在特定時間執行的 PHP 腳本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

是否有一種簡單的方法可以讓 php 腳本在一天中的特定時間執行一些 html?

Is there a simple way to have a php script execute some html at a certain times of the day?

例如,我的主頁上有一個標題,有時我希望能夠在標題下添加一些內容,在本例中為 iframe.

For example i have on my home page a header and at certain times i want to be able to add something right under the header, in this case a iframe.

我知道每個人都提到了 cron 工作,但這將如何工作?還有其他選擇嗎?并非在所有主機上都可用

I know everyone mentioned cron jobs but how would this work with that? also is there an alternative? Its not available on all hosting

推薦答案

cron 和計劃作業的想法似乎與您實際嘗試做的事情背道而馳.如果您只想在特定時間顯示某些內容(在本例中為 iframe),您只需檢查每個請求期間的服務器時間,并選擇在給定時間段內顯示它.

The idea of cron and scheudled jobs seems to run counter to what you're actually trying to do. If you want something to display (an iframe in this case) only during certain times, you can simply check the server time during each request, and opt to display it if you're within a given time period.

這樣的事情將產生與 cron 作業相同的效果,但粒度更細,在發出請求的確切時刻檢查時間.

Something like this will produce the same effect as a cron job, with more granularity, checking the time at the exact moment the requst is made.

<!-- Your Header here -->

<?php
$hour = date('G'); // 0 .. 23

// Show our iframe between 9am and 5pm
if ($hour >= 9 && $hour <= 17) { ?>
  <iframe .... ></iframe>
<?php } ?>

您可以擴展條件語句以每天多次顯示 iframe,或者讓您的腳本檢查您希望用來管理 iframe 顯示的任何外部條件.

You can expand on the conditional statement to show the iframe multiple times per day, or have your script check whatever external condition you're looking to use to govern the display of your iframe.

更新:可以通過諸如

<?php 
$hour = date('G');
$day  = date('N'); // 1..7 for Monday to Sunday

if (($hour >= 5  && $hour <= 7)  // 5am - 7am
||  ($hour >= 10 && $hour <= 12) // 10am - 12 noon
||  ($hour >= 15 && $hour <= 19) // 3pm - 7pm
||  ($day == 5)                  // Friday
) { ?>
  <iframe...></iframe>
<?php } ?>

使用服務器端 cron/任務調度程序作業定期從標頭下方添加/刪除 iframe 的想法比在每個請求期間簡單地有條件地顯示它要復雜得多.

The idea of periodically adding/removing the iframe from below your header with a server-side cron/task scheduler job is far more complex than simply conditionally displaying it during each request.

即使您有一些必須運行的特定任務,例如定期生成的報告,顯示結果的實際工作通常也不會落在定期任務上.負責顯示 iframe 的 PHP 腳本仍會在發出請求以顯示任何新內容時查詢數據庫,并在找到時顯示它,而不是定期任務以某種方式修改腳本以包含 iframe.

Even if you have some specific task which must run, such as a periodically generated report, the actual job of displaying the results usually don't fall upon the periodic task. The PHP script responsible for showing that iframe would still query the database at the time the request is made for any new content to show, and display it if found, rather than the periodic task somehow modifying the script to include an iframe.

這篇關于在特定時間執行的 PHP 腳本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国内自拍视频在线观看 | 日韩精品一二三区 | 国产精品高潮呻吟久久 | 成人h片在线观看 | 日本免费视频在线观看 | 午夜影院在线 | 一区二区三区免费 | 毛片一区二区三区 | 日韩久久网 | 久久免费精品 | 超碰97人人人人人蜜桃 | 亚洲永久| 天天躁日日躁狠狠的躁天龙影院 | 国产伦精品一区二区 | 天堂网色 | 久久精品视频免费看 | 欧美成人一区二免费视频软件 | 美女啪啪国产 | 欧美日韩国产在线观看 | 欧美成人第一页 | 日日操操 | 国产精品毛片一区二区在线看 | 日韩电影免费在线观看中文字幕 | 9191av| 老司机精品福利视频 | 在线观看亚洲专区 | 国产精品国产精品国产专区不片 | 国产乱精品一区二区三区 | www国产成人免费观看视频,深夜成人网 | 欧美成人猛片aaaaaaa | 日韩在线日韩 | av网站在线看 | 偷拍亚洲色图 | 成人免费在线视频 | 久久亚洲春色中文字幕久久久 | 国产精品久久久久免费 | 日韩精品一区二区三区四区视频 | 精品欧美一区二区三区久久久 | 亚洲日本中文 | 久久久久国产精品 | 欧美激情久久久 |