The installed php on CentOS/RHEL is the CGI version. This means I should be able to get command line arguments with $GLOBALS['argv'] or $_SERVER['argv']. That's how the php documentation tells and how it works f.i. on Suse. However, on CentOS I get them only when I use the -n switch to php (no php.ini). The problem with -n is that php cannot find the mysql_connect function for some unknown reason.
So, how can I get to argv without using -n? Or can I add the cli version with an additional rpm? I search with yum for php-cli and cli-php, but didn't find such a package.
Kai
On 3/30/06, Kai Schaetzl maillists@conactive.com wrote:
The installed php on CentOS/RHEL is the CGI version. This means I should be able to get command line arguments with $GLOBALS['argv'] or $_SERVER['argv']. That's how the php documentation tells and how it works f.i. on Suse. However, on CentOS I get them only when I use the -n switch to php (no php.ini). The problem with -n is that php cannot find the mysql_connect function for some unknown reason.
So, how can I get to argv without using -n? Or can I add the cli version with an additional rpm? I search with yum for php-cli and cli-php, but didn't find such a package.
The mysql functionality is loaded as a module which is included from php.ini. If you don't load php.ini, you get no mysql.
-- "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety'' Benjamin Franklin 1775
Jim Perrin wrote on Thu, 30 Mar 2006 19:59:03 -0500:
The mysql functionality is loaded as a module which is included from php.ini. If you don't load php.ini, you get no mysql.
Ah, makes sense, thanks. Do you know why I need the -n switch to get at these arguments on CentOS?
Kai
On Fri, 2006-03-31 at 02:29 +0200, Kai Schaetzl wrote:
The installed php on CentOS/RHEL is the CGI version. This means I should be able to get command line arguments with $GLOBALS['argv'] or $_SERVER['argv']. That's how the php documentation tells and how it works f.i. on Suse. However, on CentOS I get them only when I use the -n switch to php (no php.ini). The problem with -n is that php cannot find the mysql_connect function for some unknown reason.
So, how can I get to argv without using -n? Or can I add the cli version with an additional rpm? I search with yum for php-cli and cli-php, but didn't find such a package.
http://www.php.net/manual/en/ini.core.php#ini.register-argc-argv
Ignacio Vazquez-Abrams wrote on Thu, 30 Mar 2006 20:31:05 -0500:
http://www.php.net/manual/en/ini.core.php#ini.register-argc-argv
Ignacio, I do not want to access $argv[]. I want to access argv according to the documented way, however, this works on CentOS only if I use the -n switch. This is not like it is on other distributions and it is different than the php documentation says. Yes, I'm fully aware that this is very surely a problem in RHEL and CentOS just inherits it. I don't blame anyone for this, I just ask for information. This "tiny" change means that you have to use a different config file for command line usage of php because it's pretty useless without command line arguments or mysql.
Kai
On Fri, 31 Mar 2006, Kai Schaetzl wrote:
The installed php on CentOS/RHEL is the CGI version. This means I should be able to get command line arguments with $GLOBALS['argv'] or $_SERVER['argv']. That's how the php documentation tells and how it works f.i. on Suse.
with an utterly stock Centos, this code fragment 'just works', including database access:
[herrold@centos-4 gnuplot]$ grep -v ^$ plots.php | grep -v ^#$ \ | head -20 #!/usr/bin/php -qc/etc <?php $screen = 1 ; $screen = 0 ; $ARGC = $_SERVER["argc"]; $ARGV = array(); $ARGV = $_SERVER["argv"]; // include("/home/herrold/shim/database_trender_keying.php"); include("/home/herrold/shim/database_trender_open.php"); include("/home/herrold/shim/database_beancounter_keying.php"); include("/home/herrold/shim/database_beancounter_open.php"); // $demog_value = array(); // $nonce = $ARGC ; $counter = 0 ; // print "$ARGC: \n"; while ( $nonce > 1 ) { $nonce -= 1 ; $counter += 1 ; ...
-- Russ Herrold
R P Herrold wrote on Mon, 3 Apr 2006 09:51:08 -0400 (EDT):
#!/usr/bin/php -qc/etc
Hahaaaa, thank you very much, that does the trick! Seems that if not running with -c it doesn't grab the php.ini at all while I actually thought it used the php.ini right-away and when I used -n it doesn't. Actually, it doesn't with or without -n it seems.
Kai