How to edit php.ini values using PHP functions?

217

I currently using online server and i need to enable thecURL module (change ;extension=php_curl.dll to extension=php_curl.dll in php.ini file). But this file is not accessible and not editable for that online server. How to solve this problems using PHP functions?

107

Answer

Solution:

You might want to have a look atini_set.

PHP Doc link: http://www.php.net/manual/en/function.ini-set.php

string ini_set ( string $varname , string $newvalue )

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

Also, as they say in the documentation:

Not all the available options can be changed using ini_set(). There is a list of all available options in the appendix.

603

Answer

Solution:

The author's real reason for wanting to ini_set() directives dynamically is to access a statically compiled library (curl) in a shared hosting environment. This is not possible in the case of a library which MUST be statically compiled into PHP. The answers are valid for the title of the question but not for the description as what he's attempting to achieve seems impossible given those constraints.

However, you can use the dl() function to dynamically load modules at runtime (if they are not static) http://de1.php.net/manual/en/function.dl.php.

However, curl needs to be statically compiled into PHP...

To use PHP's cURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the include directory there should be a folder named curl which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the lib directory. Beginning with PHP 4.3.0 you can configure PHP to use cURL for URL streams --with-curlwrappers . This feature was moved to PECL as of PHP 5.5.0.

Perhaps if you just need to make a HTTP request, try file_get_contents (http://php.net/manual/en/function.file-get-contents.php), you rarely need curl in practice.

167

Answer

Solution:

You can use the php's ini_set();

an example::

ini_set("memory_limit","1000M");

Check with your hosting provider to enable curl module.

People are also looking for solutions to the problem: php - how to handle SQS re-sending the same message to the requestor

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.