程序员 - 如何定时执行一段PHP程序,不用linux或者windows上面的计划任务?
如何定时执行一段PHP程序,不用linux或者windows上面的计划任务?
回复内容:
如何定时执行一段PHP程序,不用linux或者windows上面的计划任务?
如果不用外部的定时器,那就只能用下面两个方法了
1,启动一个php进程一直在后台跑,做个定时器,检查有没有任务应该执行
2,通过用户在前台激发事件,有用户访问,则去检查有没有需要执行的任务
ps,这个蛋疼的需求在什么情况下才会遇到?
php页面的话(也就是可以通过web访问),可以用第三方的网页监控,最短五分钟一次。
不然我想不出来什么样的环境不能用crontab。
php不能常驻内存,除非你是在命令行里运行。所以说如果是web方式运行php,是实现不了这个功能的。
我们公司的奇葩做法,使用数字浏览器的自动刷新功能。。
<code>ignore_user_abort(); set_time_limit(0); </code>
在程序中while(true)死循环并判断时间,到了就执行。
为了方便控制也可以读一个文件,如果文件为0就exit,这样可以通过修改文件内容来控制进程结束。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Using python in Linux terminal...

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...
