Pecl uuid error (uuid_make() is not a function) - php

I've install UUID using pecl and then i add the extension to php.ini.
The extension is correctly loaded but i get the error
PHP Fatal error: Call to undefined function uuid_make()
This is my code :
<?php
$uuid = v4();
echo $uuid;
function v4() {
$context = $uuid = null;
uuid_create($context);
uuid_make($context, UUID_MAKE_V4);
uuid_export($context, UUID_FMT_STR, $uuid);
return trim($uuid);
}
?>
Why i'm getting this error?
If i print the list of available function i don't have neither uuid_make and uuid_export.
Hi search around the web but i always find someone who use uuid_make and uuid_export.
I can't find documentation about this module.
Thanks

The uuid_make and uuid_export are from the OSSP uuid extension, which is completely different from the PECL extension (although they both have a function named uuid_create).
The PECL extension has very little documentation and several limitations (at least from what I can tell scanning the source, e.g., no support for UUID V5). The OSSP extension is complete but must be installed from source.
If you only need to occasionally generate UUIDs, one simple alternative could be installing a uuid utility (e.g., apt-get install uuid) then use something like exec.

Related

PHP Version 7.3.17 on Amazon EC2 missing sodium?

When making call to sodium_crypto_pwhash_str I get the following in my Apache error log file.
PHP Fatal error: Uncaught Error: Call to undefined function
sodium_crypto_pwhash_str()
My php version, as noted is 7.3.17 running on an Amazon EC2 instance.
My php-info() does not return any relevant libsodium information other than module author info:
Sodium Frank Denis
Given the above author information references a module author am I supposed to enable the sodium module? If the answer is yes is it referenced in the php.ini file? Such as:
extension=sodium
or perhaps:
extension=libsodium
What am I missing here?
Am I not supposed to use the documented function sodium_crypto_pwhash_str?
Am I supposed to use some other method of accessing the desired functionality?
Yes normally it's included in PHP 7.2+ but when you use the AWS EC2 instances this is a bit minimalistic and not everything is included.
https://www.php.net/manual/de/sodium.installation.php
Here you can see that you have to enable it during the compiling with --with-sodium[=DIR]. So you can compile it on your own or you try another distro to get it from your package manager or you use another lib to make it work.
https://forums.aws.amazon.com/thread.jspa?threadID=293187

PHP class 'Ds\Map' not found

In PHP (version 7.1), I am attempting to use a MAP as opposed to a two dimensional array to handle implicit data type conversion across different data type groups. However, I am receiving the following run-time error:
Class 'Ds\Map' not found
The error occurs on this line of code:
protected $hive_data_type_group_map = new \Ds\Map();
I have checked online, but there is little documentation on Ds\Map, even on PHP's website (click here). Does anyone know how to fix this?
Data Structures is not a built-in PHP extension.
It needs to be installed before use. The installation instructions are available on php.net.
For windows
Download compiled-dll file "php_ds.dll" from https://pecl.php.net/package/ds. Place it in your dir wamp\bin\php\[your_php_version_folder]\ext and include it in your ".ini" file.
It worked for me.
the easiest way on ubuntu:
pecl install ds
Reference: https://www.php.net/manual/en/ds-deque.allocate.php

Make a proper JSON string without using json_encode [duplicate]

I'm very very new to PHP, but now I have to help my friend to solve a PHP problem.
He has bought a web site based on PHP, after he upload it to the host, found there is a error:
Fatal error: Call to undefined function json_encode() in xxx.php
The code is very simple:
echo json_encode(array(
'result' => true,
));
It send a json to client.
I know json_encode is added after php 5.2, but the PHP version of his host is PHP 5.1.2, so that's the reason why it reports error.
But we don't have the right to upgrade the PHP version of host, so I have to modify the code. How to let it return a json to client without json_encode?
The webpage in client browser will run this javascript code, to get and check that json:
jQuery.ajax({ 'url': '...', ...,
'success':function(json) {
if(json != null && json.result == true) {
// do something
}
}
}
Thanks a lot!
UPDATE
Since I have no rights to upgrade anything or install new libraries to that host, the only thing I can do is change the code. But I nearly know nothing about php, that I don't know how to use 3rd party libraries either. At last, I fix it as this:
In php:
echo '{"result":"true"}';
In javascript:
if(json!=null && json.result=="true") {
// do something
}
First of all: you should strongly consider upgrading, since PHP 5.1.x and 5.2.x are no longer supported. You indicated that you do not have the rights to do so, but if you are a paying customer, that should count for something. PHP 5.2 is deprecated as of the last PHP 5.3.6 release.
A user on PHP.net has provided for a custom function that does the same.
You could rename it to json_decode() and wrap it in a if (!function_exists('json_encode')) statement:
if (!function_exists('json_encode')) {
function json_encode() {
// do stuff
}
}
He has an older PHP version where json_encode is missing. This can be fixed with various 3rd party libraries.
A dated project of mine: http://include-once.org/p/upgradephp/ which provides a drop-in json_encode/json_decode almost identical to PHPs builtin extension (quirky in regards to Unicode).
Then there is https://pear.php.net/package/Services_JSON which even adds JSOL (Object Literals are a superset of JSON) support.
And also http://framework.zend.com/manual/en/zend.json.html which provides a class delivering a pretty thorough reimplementation. (Probably the best-tested version available.)
You can use a third party JSON library, such as the one from the PEAR project (they provide all sorts of useful PHP libraries, of varying quality):
http://pear.php.net/pepr/pepr-proposal-show.php?id=198
I'm sure there are more (I'd try searching Google for PHP JSON libraries).
Why not use a plain PHP json-library which you can include in every setup?
I googled this one here for you.
Read the comments for json_encode at http://www.php.net/manual/en/function.json-encode.php where you also find a comment containing a manual implementation for php < 5.2:
http://www.php.net/manual/de/function.json-encode.php#100835
Further there are also other implementations available via google.
jsonwrapper implements the json_encode function if it is missing, and leaves it alone if it is already present. So it is nicely future-compatible.
i had to install JSON Libs the other day on my server, try the following:
Execute the following commands:
pecl install json
touch /etc/php.d/json.ini
echo "extension=json.so" > /etc/php.d/json.ini
service httpd restart
The first will install the json libraries to your machine, the second line will create the json.ini fiel in the php.d directory and the last line will add the line extension=json.so to the json.ini file.
Hope this helps!

PHP - Call to undefined function http_inflate()

i am trying to create a module that makes a call to the stackexchange API which returns a gzipencoded or a deflated Json response. to decompress it i am using the method http_inflate but i am getting the following error:
Fatal error: Call to undefined function http_inflate()
Is this method dependent on any library or extension?
I am running PHP 5.3.13
http_inflate is not bundled with PHP. It is part of the HTTP library. See this page for instructions on how to install it.
You need to install the HTTP extension, as seen in the link below:
PHP.net: Installing the HTTP plugin
You need to install an extension (pecl_http). See here on php.net for information.

Using the Maxmind geo IP database without GeoIP PECL extension?

I'm trying to upload my files on free webhosting, to trial. I'm getting a problem with the output of client ip locator. I'm using maxmind database. "GeoIP.dat"
<?php
print geoip_database_info(GEOIP_COUNTRY_EDITION);
?>
and the output is
Fatal error: Call to undefined function geoip_database_info() in /home/u_fg176/public_html/index.php on line 15
Is it the function geoip_database_info() not found because this hosting doesn't install pecl ext for php? Or could there be another cause of this error?
It's indeed because your host didn't install the PECL extension. You can use the somewhat equivalent PEAR extension Net_GeoIP instead, which is written in PHP and can simply be included in your project:
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Net_GeoIP');
require_once 'Net_GeoIP/Net/GeoIP.php';
$GeoIP = Net_GeoIP::getInstance(GEOIP_COUNTRY_EDITION);
$location = $GeoIP->lookupLocation($ipAddress);
Yes that would be the reason. Ask them to enable or extension, or look for an alternative if they don't cooperate.

Categories