将cron作业从通过url(curl)调用更改为通过本地命令行(PHP)调用 [英] Change a cron job from calling via url (curl) to calling via local command line (PHP)

查看:261
本文介绍了将cron作业从通过url(curl)调用更改为通过本地命令行(PHP)调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cron文件名为 cron.php
在其中我使用 curl_multi 方法启动子并行任务。

I have one cron file with name cron.php. Inside it I'm using curl_multi approach to start sub parallel tasks.

示例:
cpanel的crontab将每分钟执行一次。

Example: The crontab of cpanel will execute this every minute.

curl http://mywebsite.com/cron.php

内部 cron.php c> curl_multi 调用另一个名为 sub-crons.php 的代码。第一个是 http://mywebsite.com/sub-crons.php?cron_key=1 ,第二个是 http://mywebsite.com/sub-crons.php?cron_key=2 等。

Inside cron.php I have curl_multi code that call another file called sub-crons.php. The first one will be http://mywebsite.com/sub-crons.php?cron_key=1, second will be http://mywebsite.com/sub-crons.php?cron_key=2 and so on.

这是问题,我想使用php命令像这样:

And this is the problem, I want use the php command like this:

php /path/to/my/cron.php

我可以用第一个 cron.php 文件,但它会调用其他文件(对于子任务在url,我想要它在PHP中调用 path / to / sub-crons.php?cron_key = 1 )。

I can do that with the first cron.php file but it will call the other file (for sub tasks in url and I want it to call it in PHP path/to/sub-crons.php?cron_key=1).

我可以这样做吗?

推荐答案

磁盘上的文件没有查询参数。查询参数仅用于 网址,在命令行上执行本地文件时,这些参数不相关。

A file on disk doesn't have query parameters. Query parameters are only used in URLs, which are irrelevant when executing a local file on the command line.

您的调用需要看起来更像:

Your invocation needs to look more like:

php path/to/sub-crons.php 1

在脚本中,您需要使用 $ argv [1] 参数而不是 $ _ GET

Inside the script you need to use $argv[1] to retrieve the parameter instead of $_GET.

这篇关于将cron作业从通过url(curl)调用更改为通过本地命令行(PHP)调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆