domino
domino

Reputation: 7345

Cronjob issue. Doesn't recognize variable

Works:

php -q /home/site/public_html/cron/file.php

Doesn't work:

php -q /home/site/public_html/cron/file.php?variable=1

Any suggestions? I need to send the variable as $_GET (or not)

Upvotes: 1

Views: 696

Answers (4)

Sandeep Rajoria
Sandeep Rajoria

Reputation: 1239

do it something like this

curl http://hostname/cron/file.php?variable=1

and in the file.php you will be managing the code to get the $_GET[variable]

this woould behave as a simple browser call but only in your shell/terminal

Hope this helps

Upvotes: 1

Tyler Eaves
Tyler Eaves

Reputation: 13121

The easiest way to work around this (assuming public_html, is, well, public WWW), is to have cron call wget or curl to access the PHP file, so URL variables are processed as normal.

Upvotes: 0

Nurickan
Nurickan

Reputation: 304

-q means no head, so there is no space for the get-fields i assume, at least i hope so :D

Greetz

Upvotes: -1

vstm
vstm

Reputation: 12537

Command Line arguments are passed in $argv instead of the normal $_GET/$_POST-Arrays

Of course this does not work with URI-style parameters (that ?variable=1-part). So you have to call it like: php -q /path/to/script.php 1.

As an alternative you could use getopt:

<?php
$shortopts  = implode("", array(
    "v:"
));

$longopts  = array(
    "variable:",     // Required value
);


$options = getopt($shortopts, $longopts);
var_dump($options);

And call it like php -q /path/to/script.php --variable=1.

Upvotes: 1

Related Questions