All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to pass parameters from bash to php script?
I have a php script that I want to call from a bash script, but it needs parameters. I googled and found that I need to call the php script like this:
php /path/to/script/script.php -- 'op=deletestats&id=1&verify=yes'
The 'normal' http link to call the script is: http://127.0.0.1/path/to/script/script.php?op=deletestats&id=1&verify=yes
But I also need to modify my PHP script to use parse_str(), like so:
parse_str($argv[1]);
But where/how do I modify my PHP script to use parse_str()? Do I just add it at the top of the file ?
This is the php script I want to pass the parameters to:
http://www.phpkode.com/source/p/ultrastats/ultrastats-0.3.16/ultrastats-0.3.16/src/admin/parser-shell.php
Thanks!
Comments
if you're storing the parameter into a variable, then yes
You can run make PHP scripts to 'act' like regular shell scripts by adding this to the beginning of the file:
#!/path/to/php
Then just use $argv like you'd normally use.
parse_str($argv[1]);
What about using explode() on & for the correct $argv value instead?
I'm working on a project that uses a few PHP scripts. I've set up my scripts to have more of a standard POSIX command line format (option names start with --, a space after the option name, then the value). Like this:
Here's the code that I use for parsing the input then...
I know it's not exactly what you want (but I thought I would share since it could be useful to you or someone else) - (parse_str($argv)) at the top should handle your usage scenario properly. Beware that if you want the script to work properly from the command line AND from the browser, you may have to check whether PHP is running under the cli or the browser. I would do that as follows:
Hope all of that was helpful
Sorry to give this a bump, but I am still struggeling with this. I just picked up this project again, since the log file of the server is so huge, it currently takes about 30 mins to process.
Therefore I really need a way to automate the deletion of the stats. I am still confused how the whole $argv thing works in my case. Examples from scratch are nice, but how do you modify an existing script?
Thanks
It doesn't answer your specific question, but you could put the following in your BASH script:
curl "http://somehost/path/to/script/script.php?op=deletestats&id=1&verify=yes"
@xmob Thanks, I'll try it out
You can still use
argc
@NickM and logical to increment past used arguments.EDIT: I just ran the code above. It highlighted the
cgi
typo and to check if the next argument exists.I had a brainfart and tried to comment out the complete part that was asking for a confirmation in the php file, and that actually worked! Thanks guys