jtravis Posted April 10, 2006 Share Posted April 10, 2006 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=value2Is this possible?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/ Share on other sites More sharing options...
kenrbnsn Posted April 10, 2006 Share Posted April 10, 2006 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=value2And 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 value2and 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 Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25397 Share on other sites More sharing options...
jtravis Posted April 10, 2006 Author Share Posted April 10, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25490 Share on other sites More sharing options...
trq Posted April 10, 2006 Share Posted April 10, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Is the $argv an associative array as well?[/quote]No. Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25493 Share on other sites More sharing options...
jtravis Posted April 10, 2006 Author Share Posted April 10, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25550 Share on other sites More sharing options...
trq Posted April 10, 2006 Share Posted April 10, 2006 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 Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25559 Share on other sites More sharing options...
jtravis Posted April 10, 2006 Author Share Posted April 10, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/#findComment-25563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.