crontab -e 新建/编辑一个任务
crontab -l 列出所有任务
crontab 格式:
基本格式 :
分钟 小时 日 月 星期 命令
第1列表示分钟1~59 每分钟用或者 /1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列 表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
执行PHP脚本:
* * * * * /usr/bin/php -f /root/test.php >> test.log
表示“每隔一分钟执行test.php文件,脚本的结果输出到test.log里”。 注意目录问题。
比如test.php里的代码可以是echo date("Y-m-d H:i:s") \n这种。
由于我是第一次用crontab,测试发现bin/php 这种方式只能单PHP文件可以完成的任务,如果涉及到include,require,要注意路径问题,涉及到“类(class)”似乎就不行了。希望哪位指点一下。
另外需要注意这个脚本需要有执行权限。
而我本人需要完成的任务是定时访问一个文件(链接)去生成sitemap,所以访问URL就不能用bin/php 去完成,而是要用bin/curl。所以我的代码就成了下边这样:
* * * * * /usr/bin/curl http://aa.com:8080/tools/sitemap.php >> /Desktop/untitled.html
关于这个命令里后边的输出,并不是必须的,只是为了方便在写命令的时候调试。
关于crontab命令的参数建议看一下手册,这里只复制了一段查到的资料里提到的。
本站@Jacendfeng 的这篇Linux 下执行定时任务 crontab 命令详解 写的非常详细,建议看一下。
参考资料:
鳥哥的 Linux 私房菜 -- 第十五章、例行性工作排程(crontab)
linux 自动执行 crontab学习笔记
linux定时调用指定url链接,linux crontab定时执行php脚本程序介绍
linux使用crontab实现PHP执行定时任务

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools