PECL_HTTP not recognised php ubuntu - php

I am trying to use the HttpRequest class which should be in the PECL_HTTP extension of php.
I have php5 and used the following to install pecl_http.
sudo pecl install pecl_http
pecl/pecl_http is already installed and is the same as the released version 2.0.1
install failed
After that i enter into my php.ini:
[PHP]
extension=http.so
[...]
Then i restart my apache2 server, and try using the HttpRequest class, but it gives me the following error:
PHP Fatal error: Class 'HttpRequest' not found
What are possible error's i might have missed?
UPDATE: (Changed the title)
The Extension is not shown in phpinfo(), i set
extension=http.so
And checked if the http.so file is in my extension_dir. I really don't know how to make php recognise the extension.
UPDATE 2:
I managed to install extension, but the class still does not exist.
For others, i had to reference the other extensions pecl_http needs. (For me: propro.so, raphfr.so)
UPDATE 3:
I did not manage to make the Class visible, the answers below show some approaches with other classes.
I solved this issue by using CURL.

You have installed the new version of the extension which uses a completely different API. I still don't know how it works, but I will update my answer one I know. The Documentation of the new version is to be found at http://devel-m6w6.rhcloud.com/mdref/http.
To Install the old version, first uninstall the new verion and then execute
pecl install http://pecl.php.net/get/pecl_http-1.7.6.tgz
UPDATE: here are two examples from the documentation, both should work well:
one request (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/enqueue):
<?php
(new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"),
function(http\Client\Response $res) {
printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
return true; // dequeue
})->send();
multiple requests (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/once):
<?php
$client = new http\Client;
$client->enqueue(new http\Client\Request("HEAD", "http://php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pecl.php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pear.php.net"));
printf("Transfers ongoing");
while ($client->once()) {
// do something else here while the network transfers are busy
printf(".");
// and then call http\Client::wait() to wait for new input
$client->wait();
}
printf("\n");
while ($res = $client->getResponse()) {
printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
$res->getResponseCode());
}
In both examples you can use $res->getBody() to return the body of the response.
I couldn't test these examples but I have heard of other people that they work.

I had the same problem and solved it by arrange the order in wich extensions are loaded in php.ini
All my other extensions was loaded using their own .ini files in /etc/php5/mods_available.
In my apache2 error.log I noticed that json_decode was needed by http.so to load.
I created a file for http (http.ini) and a symlink in /etc/php5/apache/conf.d with a higher prefix than json.
my http.ini
; configuration for php http module
; priority=50
extension=raphf.so
extension=propro.so
extension=http.so
use the new pecl_http.2.0.6 like this
new http\Message();
or extend in your own class as extends http\Message

Related

How to install locally an extension in SQLite on a Mac?

I've no real knowledge about installing an extension. I'm stuck because I cannot use SQRT in SQLite.
I'm using Laravel on a local machine and I'm working on my PHPunit Tests. In one Test I'm using a query with some heavy math functions.
I get the error:
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such function: SQRT
I found out that SQLite has an extension called: extension-functions.c
I downloaded it, but I'm not sure if I did everything correctly (obviously not because it does not work):
I downloaded it and used this in my terminal
gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib
It compiled this data: libsqlitefunctions.dylib
With php --ini if found that my php.ini is located in /usr/local/etc/php/7.1/php.ini
Now I looked up for sqlite3 and found this commented ;sqlite3.extension_dir =
I changed it to
sqlite3.extension_dir =/usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
and created the extension folder and put the dylib file inside
I restarted my apache with sudo apachectl restart
And tried my Query and still, it fails. What did I do wrong?
For future readers
To use it in Laravel you call it like this:
$pdo = DB::connection()->getPdo();
$pdo->sqliteCreateFunction('SQRT', 'sqrt', 1);
$pdo->sqliteCreateFunction('ASIN', 'asin', 1);
$pdo->sqliteCreateFunction('SIN', 'sin', 1);
$pdo->sqliteCreateFunction('COS', 'cos', 1);
$pdo->sqliteCreateFunction('POWER', 'pow', 2);
$pdo->sqliteCreateFunction('pi', 'pi', 0);
It seems that you want to use this with PDO. The problem is that loading extensions only works with the SQLite3 api directly, using the SQLite3::loadExtension method.
The PDO driver does not allow the loading of extensions (see this wiki entry regarding LoadableExtensions under "Security Considerations").
So you could either swith to the SQLite3 api directly or you could use "user defined functions" with PDO. For example if you need the SQRT function:
$db = new PDO('sqlite:testdb.sqlite', null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$db->sqliteCreateFunction('SQRT', 'sqrt', 1);
$stmt = $db->query("SELECT sqrt(25)");
foreach ($stmt as $row) {
echo $row[0], PHP_EOL; // output: 5.0
}
Most of the math-functions your extension provides map 1:1 to the PHP function names (like sqrt), so it should be easy to create the functions you need.
It seems you are pointing the sqlite3.extension_dir property at a file instead of a directory. According to the manual for sqlite3, the extension_dir property is:
[The] Path to the directory where the loadable extensions for SQLite reside.
I think it may work if you change
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
to
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension
However, I would create a separate directory for the SQLite3 extensions so they are not mixed with the PHP extensions; I say this since it seems like you are currently using the PHP extension directory for the sqlite3.extension_dir property. (If you aren't, then please disregard this note.) I assume that SQLite3 just scans the configured directory for loadable modules and loads them using something like dlopen. This might conflict if it tries to load a PHP extension. (Who knows, it may gracefully handle this.)

yaml_emit_file() not working. Call to undefined function yaml_emit_file()

The php function yaml_emit_file() is not working. I have installed and included the php_yaml.dll in my php.ini file restarted the server but still when I use this function, I get this error (when I run composer):
Call to undefined function RS\composer\yaml_emit_file()
Okay so a little about the background:
PHP version 7.1.7 & Composer version 1.5.1
I am using this function in a ScriptHandler.php file which is invoked when Composer is run. In this script I have a function buildModuleList which is called on post-update-cmd event of Composer. Everything else in the code is working fine.
I am in doubt that maybe I am using this function in wrong context or something like that.
Here is the code snippet where I am using yaml_emit_file() (Providing this just for reference, tell me if am using it the wrong way!):
if (!$fs->exists($moduleListFile)) {
$fs->touch($root.'/profiles/thunder/modulelist.yml');
$fs->chmod($root . '/profiles/thunder/modulelist.yml', 0666);
if(!empty($moduleList)){
$createyml= yaml_emit_file($moduleListFile, $moduleList);
if (!$createyml){
$io->writeError('<error>Cannot create modulelist.yml</error>');
}
}
$io->write('Success: Created new modulelist.yml', $newline= TRUE);
}
else{
$fs->file_put_contents($moduleListFile, $installedPackage, FILE_APPEND);
$io->write('Success: Module entry in modulelist.yml', $newline= TRUE);
}
i hope this help someone i test it on
Windows 10
XAMPP v3.2.4
PHP 8.0.2
Download the latest YAML DLL Package from : https://pecl.php.net/package/yaml
Unzip the files
Move the php_yaml.dll file to xampp/php/ext folder
Open your php.ini in xampp/php add a new line extension=php_yaml.dll, save and exit
Restart your XAMPP Servers
make a PHP file put into
<?php
phpinfo();
?>
Search the string yaml on the page. If it says Enabled then your YAML Extension is working.

Class 'MongoDB\Client' not found, mongodb extension installed

I tried to create new mongo connection executing the following code
$m = new MongoDB\Client();
and i got this error:
Fatal error: Class 'MongoDB\Client' not found
i think i have properly installed MongoDB extension
(Copied php_mongodb.dll to ext folder and updated php.ini with extension=php_mongodb.dll).
The following code confirms it is loaded:
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
I still receive the same error.
Here is
phpinfo()
I appreciate all your help. Thank you!
If you are using latest MongoDB extension of PHP, MongoDB\Driver\Manager is the main entry point to the extension.
Here is the sample code to retrieve data using latest extension.
Let's say you have testColl collection in testDb. The you can retrieve data using MongoDB\Driver\Query class of the extension.
// Manager Class
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));
// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $manager->executeQuery('testDb.testColl', $query);
// Convert cursor to Array and print result
print_r($cursor->toArray());
Output:
Array
(
[0] => stdClass Object
(
[_id] => MongoDB\BSON\ObjectID Object
(
[oid] => 5848f1394cea9483b430d5d2
)
[name] => XXXX
[age] => 30
)
)
I'm using PHP 7.1.9 and I had this issue. Solved it by removing and reinstalling mongodb/mongodb
composer remove mongodb/mongodb
composer require mongodb/mongodb
Also, If you are using Dreamweaver, don't for get to put the vendor folder in the server copy.
After installing, I can now use MongoDB\Client.
mongodb API Version 1.3, Mongodb Extension 1.4
same happened with me, check the version of php install on your server.
You have to use php version 5.6 .Check the apche error log to get more precise error detail.
Just simple way to install
sudo apt-get install php-mongodb
after install mongo
Different for Apache and Nginx it appears.
Though this post is old but I help this migh help someone. I recently ran into same problem. With me it was s different php.ini.
I kept placing the mongoextension into /cli/php.ini.
Thoough when I ran <?php phpinfo() ?> I found out that in my case the loaded configuration is in /fpm/php.ini. This was because I was unsing Nginx with fpm.
90% of the time it is your Mongodb extension configuration. kindly check in php.ini
\MongoDB\Driver\Manager(); is now "low level" extension (php_mongodb), \MongoDB\Client was rewritten to "PHP class" and you need extra install https://docs.mongodb.com/drivers/php/ to use old style nice new \MongoDB\Client('mongodb://127.0.0.1');

Install ingres extension for php on my WAMP server

I've a development computer, which runs under windows.
For a project, I've to make a php website which has to connect to an Ingres database server.
So I installed wamp, I installed ingres(server and client, on my local machine).
I added the library that I found on their site(php_ingres.dll) in the C:\wamp\bin\php\php5.3.5\ext folder, and I added a line "extension=php_ingres.dll" in the configuration file.
I shutdown wamp and restarted it, and I restarted the server, I see now a check mark in the wamp menu, indicating that php_ingres is now activated. But when I go to the welcome page of the server, I don't see this extension as loaded. If I go on the php info page, I don't see any Ingres entry in the Configure Command.
I just can't found any post/tutorial/... which indicating how to do this operation, so any help would be appreciated!
Thank you!
Edit: I made a small test to see if I can connect to an Ingres database:
<?php
$link = ingres_connect("localhost", "demodbtest", "demodbtest") or die("Connexion impossible");
echo "Connexion réussie";
$result = ingres_query($link,"select * from airline");
while ($row = ingres_fetch_array($result)) {
echo $row["al_iatacode"]; // utilisation du tableau associatif
echo $row["al_name"];
echo $row["al_ccode"]; // utilisation du tableau à indices numériques
echo "</br>";
}
ingres_close($link);
?>
And I get this error:
( ! ) Fatal error: Call to undefined function ingres_connect() in
C:\wamp\www\tests\index.php on line 2
Some information on my installation:
I've a windows 7 pro 32bits
Wampserver 2.1 ( http://sourceforge.net/projects/wampserver/files/WampServer%202/WampServer%202.1/WampServer2.1e-x32.exe/download )
Apache 2.2.17
PHP 5.3.5
Ingres 10.1.0 Community edition( downloaded here: http://esd.ingres.com/product/Community_Projects/Ingres_Database/Windows_32-Bit/Ingres_10.1_Build_121/ingres-10.1.0-121-gpl-win-x86-NoDoc.zip/http )
PHP drivers downloaded here: http://esd.ingres.com/product/drivers/PHP/Windows_32-Bit/PHP_Driver
To practically test if the extension was loaded you can as well call one of it's functions. If the extension was loaded, you should not get a fatal error for a missing function. That's perhaps one of the quickest checks.
Another check is to make use of extension_loaded *PHP Manual** which will give you a list of all loaded extensions. See the PHP Manual link above for more info.
The configure line
The configure line will not show the ingres extension because it has not been compiled in. That's perfectly alright because you load it as an extension (.dll) so it's not part of php.exe. This is why you don't see it in the configure line.
Locating ingres on the phpinfo() page.
On the phpinfo()-page use the search function inside your browser (often CTRL+F) and try to locate the word ingres. You should locate a section that displays the extensions default settings if it has been loaded.
The following is an example screenshot for the xdebug extension. This might look similar for ingres:
Image from: Launching xdebug in Eclipse stuck at 57% - How to trouble-shoot?
Double check your extension_dir setting as well as the actual php.ini file being used. Calling php.exe -i from the command line might not give the same output if executing phpinfo() in a script via Apache (or IIS). In fact http://www.wampserver.com/en/faq.php says there are 3 potential php.ini scripts.
The problem is that I wasn't having the ingres client installed locally, so it appears that this lib cannot works without it

PHP: "independent" function to replace mime_content_type?

Is there any available, "independent" function which could replace mime_content_type()?
On my new hosting I'm getting error:
Fatal error: Call to undefined function mime_content_type() in download.php on line 3
finfo_file doesn't work as well...
Just mimic the function in your compat.php if you have one
if(!function_exists("mime_content_type"))
{
function mime_content_type($file)
{
$open_bit = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($open_bit, $file);
}
}
The above function (FileInfo) is a PECL extension and is encouraged by PHP To use as an alternative, if you do not have the extension installed you can do the following:
Find the url to the latest version of fileinfo from http://pecl.php.net/package/Fileinfo
Download, compile and install
Run the following commands
wget http://pecl.php.net/get/Fileinfo-X.X.X.tgz
gunzip Fileinfo-X.X.X.tgz
tar -xvf Fileinfo-X.X.X.tar
cd fileinfo-X.X.X
./configure
make
make install
Enable the extension by adding extension=fileinfo.so to your php.ini
Restart your web server and it should be working.
And then proceed as normal
As a matter of fact, there are two indepent implementations. One in http://upgradephp.berlios.de/ and one in PHP_Compat. You need the mime-magic file in either case.

Categories