Jump to content

Archived

This topic is now archived and is closed to further replies.

jtravis

PHP Cron and $_GET values

Recommended Posts

Hey all! I was wondering if anyone would know how to run a php script from a shell script or cron job and pass $_GET data to it?

I have a script for my cart (that was a module that I didn't code) that generates a file to be uploaded to Froogle. So basically, I'm wanting something like this in my script.

php -q /path_to_file/file.php?data1=value1&data2=value2

Is this possible?


Thanks!

Share this post


Link to post
Share on other sites
The $_GET & $_POST superglobal arrays are only filled when your script is invoked via a web server. When invoked via the command line, parameters are passed in the $argv array, just like C.

In you case, you should invoke it in one of these ways:[list][*]php -q /path_to_file/file.php data1=value1&data2=value2
And then use the [a href=\"http://www.php.net/parse_str\" target=\"_blank\"]parse_str[/a]() function to get the values:
[code]<?php parse_str($argv[1]) ?>[/code][*]php -q /path_to_file/file.php value1 value2
and process it like
[code]<?php for ($i=1;$i <= $argc; $i++) $data[$i] = $argv[$i] ?>[/code][/list]The first index of $argv (i.e. $argv[0]) is the script name.

Ken

Share this post


Link to post
Share on other sites
Just making sure I understand.

I would have to alter the original script to look for the $argv value instead of the $_GET values or both.

How is using parse_str() different from $_SERVER['argv'] (I was RTFM ;))?

Just curious. Is the $argv an associative array as well? Meaning instead of using a numerical index, can I reference it by name as in $_GET?

Thanks for your reply! Much appreciated!

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Is the $argv an associative array as well?[/quote]
No.

Share this post


Link to post
Share on other sites
I suppose my example was poor, or I'm just not grasping the concept.

Would this work or must I use the $argv?

[code]//Parse the text to get the values.
parse_str('download=tempfile&dltype=froogle');
//Replaced $_GET with $_SERVER in attempt to run from cli
$ep_dltype = (isset($_SERVER['dltype'])) ? $_SERVER['dltype'] : $ep_dltype;[/code]


Share this post


Link to post
Share on other sites
If this is all this cron job is going to do and these values aren't going to be in any way dynamic, why not just hard code the values into the script?

Share this post


Link to post
Share on other sites
[!--quoteo(post=363358:date=Apr 10 2006, 12:51 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Apr 10 2006, 12:51 PM) [snapback]363358[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If this is all this cron job is going to do and these values aren't going to be in any way dynamic, why not just hard code the values into the script?
[/quote]


Good point! I guess I was thinking so outside the box that I didn't think to look inside of it. I suppose part of it was I wasn't for certain how the script ran as it's a third-part mod and was wanting to see if this way would be easier. But to be honest. I never even thought of that. LMAO!

Thanks again.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.