ThurstonLevi
ThurstonLevi

Reputation: 827

run a url on command line without using curl or wget content on same server

The background to this is I have a function on a website i wish to run once a day, the cron and website or on the same server. My website is using cloudflare and my cron runs the curl command to run the function. This works about 50% of the time, the other 50% i get a 522 cloudflare error. So I need to bypass cloudlfare really to run this.

So lets say my curl was https://my-site.com/index.php?action=do-task and the path on the server to the index.php file is var/www/html/index.php

how is the best way to do this so the do-task action is passed into the index.php file?

i'm thinking something like

php /var/www/html/index.php

might work but can't work out how i would pass the action = do-task part

thanks

Craig

Upvotes: 0

Views: 270

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

If the page is already using $_GET then check for command line arguments, make them into a query string and parse them into $_GET:

if(isset($argv)) { parse_str(implode('&', $argv), $_GET); }

Then call your script like this:

php /var/www/html/index.php action=do-task

$_GET will contain:

Array
(
    [index_php] =>
    [action] => do-task
)

For more parameters just separate with a space:

php /var/www/html/index.php action=do-task foo=bar

Upvotes: 1

Related Questions