Jump to content

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!
Link to comment
https://forums.phpfreaks.com/topic/6991-php-cron-and-_get-values/
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
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!
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]


[!--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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.