Php -i | find "extension_dir" does not take effect after changing its value

I want to use curl in php script and run it in command line mode.

here is the script

<?php //enable_dl("php_curl.dll"); $ch = curl_init(); $options=array( CURLOPT_URL=>"http://test.com/wp-content/themes/bluefocus/images/desc_img.jpg", CURLOPT_BINARYTRANSFER=>true, CURLOPT_VERBOSE=>true ); curl_setopt_array($ch,$options); $data = curl_exec($ch); $fp=fopen("test.jpg","w"); fwrite($fp,$data); curl_close($ch); ?> 

I ran it in cmd using the php get.php command

error message:

 D:\project>php get.php Fatal error: Call to undefined function curl_init() in D:\project\gals_curl_batch_download\get.php on line 3 

phpinfo () on the output of the web page shows that curl is turned on

 cURL support enabled cURL Information libcurl/7.19.4 OpenSSL/0.9.8k zlib/1.2.3 

and here is the weird thing phpinfo () int in the web page output view, in fact the extension included in php.ini can be run on the web page. the exact extension directory is under. / ext

 extension_dir ./ext ./ext 

but php -i | find "extension_dir" always shows this and cannot be changed in the php.ini file

 extension_dir => C:\php5 => C:\php5 

restarted apache several times, keeps the same error. therefore, I wonder why the value of extension_dir cannot be changed.

+4
source share
4 answers

Hey guys, I found the answer to the question. simply because php -i and phpinfo () on the script network use different php.ini files.

I will seriously consider the various results of php -i and phpinfo ().

here the difference arises:

phpinfo () :

Apache 2.0 Handler API Server

Configuration File (php.ini) Path C: \ Windows

Loaded configuration file D: \ phpnow \ PHP-5.2.10-Win32 \ PHP-apache2handler.ini

php -i

API Server => Command Line Interface

Configuration File (php.ini) Path => C: \ Windows

Loaded configuration file => (none)

The main problem is that php -i does not load anything other than waiting for php.ini.

+3
source

Try copying the php.ini file to the c: \ windows directory. I am using PHP 5.3.5. and I had the same problem on Windows. When I copied the php.ini file to c: \ windows, extension_dir was installed correctly and my graphics program started working.

+3
source

Have you tried adding extension=php_curl.dll to php.ini?

FWIW, the best way to check phpinfo for the CLI is probably:

 $ php -i | fgrep -i curl Configure Command => '/SourceCache/apache_mod_php/apache_mod_php-44.4/php/configure' '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear' curl cURL support => enabled cURL Information => libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3 $ 

php -i is basically the CLI equivalent of phpinfo()

Also, double check that the PHP CLI is configured to use the same php.ini (or if it uses a different file, make sure you edit it too). Sometimes PHP can be configured using another php.inis depending on how PHP is called - I believe that debian and Ubuntu do this in particular.

Determining the php.ini file to use:

 $ php -i | fgrep Configuration Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini $ 

or

 $ php --ini Configuration File (php.ini) Path: /etc Loaded Configuration File: /etc/php.ini Scan for additional .ini files in: /etc/php.d Additional .ini files parsed: /etc/php.d/apc.ini, /etc/php.d/dbase.ini, /etc/php.d/dom.ini, /etc/php.d/gd.ini, /etc/php.d/imagick.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/memcache.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_pgsql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/pgsql.ini, /etc/php.d/tidy.ini, /etc/php.d/xdebug.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini 
0
source

Work with php 5.4.4. with Windows 7 and Apache 2.2. Running phpinfo () showed that the value assigned by extension_dir does not match the setting in php.ini

But php.ini was , of course, read.

My suspicion is that extension_dir requires a reboot on Windows and a set of PATH. Other settings in php.ini just require restarting Apache.

0
source

Source: https://habr.com/ru/post/1306482/


All Articles