Posted by:
yodude75
(---.zone2.bethere.co.uk)
Hello all,
for sometime I've been having trouble and facing a 'funny' behavior of my scripts when running in CLi aka command line.
Enviroment:
Wamp Server 2.0
Windows Vista Home Premium
PHP 5.2.6
MySQL 5.1.30
Apache 2.2.10
cURL libcurl/7.16.0 OpenSSL/0.9.8g zlib/1.2.3
Bear in mind that I manually added php to the windows path.
The script below will work fine when ran via Browser but will fail when run via command line.
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com"
;
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
?>
This is because, dunno why, when ran via Browser, Wamp Boss - Apache, reads the php.ini file that is within the folder C:\wamp\bin\apache\Apache2.2.x\bin\
and when running PHP via command line Apache reads the configuration file (php.ini) that is the folder c:\wamp\bin\php\php5.2.x\
Do you doubt?
On your browser go to http: / / localhost/?phpinfo=1 [remove the spaces]
take a look at the entry "Loaded Configuration File" should say "C:\wamp\bin\apache\Apache2.2.10\bin\php.ini"
Now open a DOS prompt window (Start > Run > (type) cmd)
on this DOS box type
c:\wamp\bin\php\php5.2.6\php.exe -r phpinfo(); |more
press CTRL+C to break.
On the result of the command you will see "Loaded Configuration File => C:\wamp\bin\php\php5.2.6\php.ini"
remember that via browser "Loaded Configuration File" was in ../Apache2.x.x/bin/
totally different locations.
So the solution is pretty simple, rename C:\wamp\bin\php\php5.2.6\php.ini to C:\wamp\bin\php\php5.2.6\php.ini.old
then COPY (not cut ) the php.ini from C:\wamp\bin\apache\Apache2.2.10\bin\ and paste in C:\wamp\bin\php\php5.2.6\
Hope this was clear and solve problems of more people !!!
all the best for all
=)