Cron 没有将参数传递给 PHP 脚本 [英] Cron not passing params to PHP script

查看:31
本文介绍了Cron 没有将参数传递给 PHP 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

php /home/novinarb/public_html/index.php --uri="cron/24satahr"

但是uri"参数根本没有到达 php 脚本.我也试过在 uri 前面没有 -- 但仍然没有.有什么想法吗?

but the 'uri' param doesn't get to the php script at all. I also tried without the -- in front of uri but still nothing. Any ideas?

推荐答案

更强大的方法是在 PHP 脚本中使用 getopt()$argv 并使其可执行.一个带有 $argv 的例子叫做 script.php:

A more robust method would be to accept command-line arguments in your PHP script with getopt() or $argv and making it executable. An example with $argv called script.php:

#!/usr/bin/php
<?php
  if (isset($argv[1])):
    echo $argv[1];
  endif;
?>

使其可执行:

chmod +x script.php

并执行:

./script.php "cron/24satahr"

将输出:

cron/24satahr

这篇关于Cron 没有将参数传递给 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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