Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5afc794
Upgrade xxHash to r49
Megasaxon Jul 6, 2015
e84410e
Upgrade xxHash to r40
Megasaxon Jul 6, 2015
2fe5a36
Add xxhash64 support
Megasaxon Jul 6, 2015
f1589a6
Merge branch 'feature/xxhash_64' into develop
Megasaxon Jul 6, 2015
e8b8c48
Update project readme to be more useful
Megasaxon Jul 6, 2015
8a9ef42
Add xxHash to credits
Megasaxon Jul 6, 2015
dc75984
Have the two xxHash functions return a digest rather than an integer.
Megasaxon Jul 6, 2015
ea9b9e2
Working PHP7 version
Megasaxon Jul 10, 2015
faf3047
Cleanup
Megasaxon Jul 13, 2015
d1d7bec
Merge branch 'feature/php7' into develop
Megasaxon Jul 13, 2015
e7975b8
Update readme to include information regarding PHP7
Megasaxon Jul 13, 2015
10ab8ca
Updating the base library to the latest version
nheimann1 Sep 20, 2015
e8091d8
Merge pull request #1 from nheimann1/develop
nheimann1 Sep 20, 2015
d2ed2c6
Adding more information to the README.md file
nheimann1 Sep 21, 2015
cdf2c7c
Remove comments to fix configure.js
jmwebservices Feb 15, 2018
9a653bf
Merge pull request #1 from jmwebservices/fix/build
Megasaxon Apr 28, 2018
a05c6e6
Remove long to string conversion
Sep 27, 2019
ae1114b
Update c files
Sep 27, 2019
afc944c
Update readme
Sep 27, 2019
d511a40
Add missing header file
Oct 2, 2019
45b9f7b
Update installation instructions
Oct 2, 2019
313c084
Support for PHP 7.
nheimann1 Dec 10, 2020
21f9b8e
Start from scratch
nheimann1 Dec 20, 2020
861e02f
Merge remote-tracking branch 'remotes/eskimi/develop' into chore/migr…
nheimann1 Dec 20, 2020
6751943
Adding again the unsigned hashing option as string (PHP doesn't suppo…
nheimann1 Dec 20, 2020
dea30cd
Merge branch 'develop'
nheimann1 Dec 20, 2020
7ab0243
Adding arguments info, without doing so a warning will be shown on PHP 8
nheimann1 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
# php-xxhash

PHP extension to add support for the [xxhash](http://code.google.com/p/xxhash/) fast hashing algorithm. _xxhash_ is designed to be fast enough to use in real-time streaming applications.
PHP extension to add support for the [xxhash - r42](https://github.com/Cyan4973/xxHash) extremely fast hashing algorithm. _xxhash_ is designed to be fast enough to use in real-time streaming applications.


## How To Install

Run
```
phpize
./configure --enable-xxhash
make
sudo make install
```

Add to the php.ini
```
extension=xxhash.so
```

Restart apache
```
sudo service apache2 restart
```


## How To Use

This extension adds one new PHP function:
This extension adds three new PHP functions:

```
// 32 bit version (all values are positive)
int xxhash32(string $data);

// 64 bit version (can return negative values since PHP doesn't support unsigned long values)
long xxhash64(string $data);

// 64 bit version (all values are positive but returned as strings)
string xxhash64Unsigned(string $data);
```

It will checksum the string, and return the checksum.
They will checksum the string, and return the checksum.

## Credits
* Original implementation of [php-xxhash](https://github.com/stuartherbert/php-xxhash) by Stuart Herbert.
* Original update to PHP 7 of [php-xxhash](https://github.com/eskimi/php-xxhash) by Eskimi.
* [xxHash](https://github.com/Cyan4973/xxHash) by Yann Collet.


## License

Expand Down
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ if test "$PHP_XXHASH" != "no"; then
dnl Write more examples of tests here...

PHP_NEW_EXTENSION(xxhash, php_xxhash.c, $ext_shared)
fi
fi
6 changes: 1 addition & 5 deletions config.w32
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// $Id$
// vim:ft=javascript

// If your extension references something external, use ARG_WITH
// ARG_WITH("xxhash", "for xxhash support", "no");

// Otherwise, use ARG_ENABLE
// ARG_ENABLE("xxhash", "enable xxhash support", "no");
ARG_ENABLE("xxhash", "enable xxhash support", "no");

if (PHP_XXHASH != "no") {
EXTENSION("xxhash", "php_xxhash.c");
Expand Down
103 changes: 64 additions & 39 deletions php_xxhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,98 @@
#include "xxhash.c"

#ifdef COMPILE_DL_XXHASH
ZEND_GET_MODULE(xxhash)
ZEND_GET_MODULE(xxhash);
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
#endif

PHP_MINIT_FUNCTION(xxhash)
{
return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(xxhash)
{
return SUCCESS;
}

PHP_RINIT_FUNCTION(xxhash)
{
return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(xxhash)
{
return SUCCESS;
}

PHP_MINFO_FUNCTION(xxhash)
{
php_info_print_table_start();
php_info_print_table_header(2, "xxhash support", "enabled");
php_info_print_table_row(2, "extension version", PHP_XXHASH_VERSION);
php_info_print_table_row(2, "xxhash release", "http://code.google.com/p/xxhash/source/detail?r=6");
php_info_print_table_row(2, "xxhash release", "r40");
php_info_print_table_end();
}

PHP_FUNCTION(xxhash32)
{
char *arg1 = NULL;
char *ret1 = NULL;
int arg1_len;
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
unsigned int sum;

/* parse the parameters */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg1, &arg1_len) == FAILURE || arg1_len < 1)
{
RETURN_NULL();
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE || arg_len < 1) {
return;
}

/* compute the checksum */
sum = XXH32(arg1, arg1_len, 0);
// compute the checksum
sum = XXH32(arg, arg_len, 0);

/* return the checksum */
RETURN_LONG(sum);
}

PHP_FUNCTION(xxhash64)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
unsigned long long sum;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE || arg_len < 1) {
return;
}

// compute the checksum
sum = XXH64(arg, arg_len, 0);

/* return the checksum */
RETURN_LONG((long)sum);
/* Negative values can be returned since we cannot return unsigned long to php */
RETURN_LONG(sum);
}

zend_function_entry xxhash_functions[] = {
PHP_FE(xxhash32, NULL)
{NULL, NULL, NULL}
PHP_FUNCTION(xxhash64Unsigned)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
unsigned long long sum;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE || arg_len < 1) {
return;
}

// compute the checksum
sum = XXH64(arg, arg_len, 0);

//Since php doesn't have unsinged long values, the value will be returned as string
char numberAsAString[21];
sprintf(numberAsAString, "%llu",sum);
RETURN_STRING(numberAsAString);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_xxhash, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_END_ARG_INFO()

const zend_function_entry xxhash_functions[] = {
ZEND_FE(xxhash32, arginfo_xxhash)
ZEND_FE(xxhash64, arginfo_xxhash)
ZEND_FE(xxhash64Unsigned, arginfo_xxhash)
PHP_FE_END
};

zend_module_entry xxhash_module_entry = {
STANDARD_MODULE_HEADER,
"xxhash",
xxhash_functions,
PHP_MINIT(xxhash),
PHP_MSHUTDOWN(xxhash),
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(xxhash),
PHP_XXHASH_VERSION,
STANDARD_MODULE_PROPERTIES
};

29 changes: 16 additions & 13 deletions php_xxhash.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#ifndef PHP_XXHASH_H
#define PHP_XXHASH_H

#define PHP_XXHASH_VERSION "1.0.1"

extern zend_module_entry xxhash_module_entry;
#define phpext_xxhash_ptr &xxhash_module_entry

#if defined(PHP_WIN32) && defined(XXHASH_EXPORTS)
#define PHP_XXHASH_API __declspec(dllexport)
#define PHP_XXHASH_VERSION "2.0"

#ifdef PHP_WIN32
# define PHP_XXHASH_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_XXHASH_API __attribute__ ((visibility("default")))
#else
#define PHP_XXHASH_API PHPAPI
# define PHP_XXHASH_API
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

PHP_MINIT_FUNCTION(xxhash);
PHP_MSHUTDOWN_FUNCTION(xxhash);
PHP_RINIT_FUNCTION(xxhash);
PHP_RSHUTDOWN_FUNCTION(xxhash);
PHP_MINFO_FUNCTION(xxhash);

PHP_FUNCTION(xxhash32);

#endif /* PHP_XXHASH_H */
#ifdef ZTS
#define XXHASH_G(v) ZEND_TSRMG(xxhash_globals_id, zend_xxhash_globals *, v)
#ifdef COMPILE_DL_XXHASH
ZEND_TSRMLS_CACHE_EXTERN();
#endif
#else
#define XXHASH_G(v) (xxhash_globals.v)
#endif

#endif /* PHP_XXHASH_H */
Loading