-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vip601115211
committed
Dec 18, 2019
0 parents
commit e3db4f6
Showing
16 changed files
with
712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
*.lo | ||
*.la | ||
.libs | ||
acinclude.m4 | ||
aclocal.m4 | ||
autom4te.cache | ||
build | ||
config.guess | ||
config.h | ||
config.h.in | ||
config.log | ||
config.nice | ||
config.status | ||
config.sub | ||
configure | ||
configure.ac | ||
include | ||
install-sh | ||
libtool | ||
ltmain.sh | ||
Makefile | ||
Makefile.fragments | ||
Makefile.global | ||
Makefile.objects | ||
missing | ||
mkinstalldirs | ||
modules | ||
run-tests.php | ||
tests/*/*.diff | ||
tests/*/*.out | ||
tests/*/*.php | ||
tests/*/*.exp | ||
tests/*/*.log | ||
tests/*/*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
language: php | ||
|
||
compiler: | ||
- gcc | ||
- clang | ||
|
||
os: | ||
- linux | ||
|
||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
# - nightly | ||
|
||
notifications: | ||
email: [email protected] | ||
|
||
env: | ||
- REPORT_EXIT_STATUS=1 NO_INTERACTION=1 | ||
|
||
before_install: | ||
- chmod +x ./travis/compile.sh | ||
- chmod +x ./travis/run-tests.sh | ||
|
||
#Compile | ||
before_script: | ||
- ./travis/compile.sh | ||
|
||
# Run PHPs run-tests.php | ||
script: | ||
- ./travis/run-tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
snowflake | ||
[email protected] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-------------------------------------------------------------------- | ||
The PHP License, version 3.01 | ||
Copyright (c) 1999 - 2011 The PHP Group. All rights reserved. | ||
-------------------------------------------------------------------- | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, is permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
3. The name "PHP" must not be used to endorse or promote products | ||
derived from this software without prior written permission. For | ||
written permission, please contact [email protected]. | ||
|
||
4. Products derived from this software may not be called "PHP", nor | ||
may "PHP" appear in their name, without prior written permission | ||
from [email protected]. You may indicate that your software works in | ||
conjunction with PHP by saying "Foo for PHP" instead of calling | ||
it "PHP Foo" or "phpfoo" | ||
|
||
5. The PHP Group may publish revised and/or new versions of the | ||
license from time to time. Each version will be given a | ||
distinguishing version number. | ||
Once covered code has been published under a particular version | ||
of the license, you may always continue to use it under the terms | ||
of that version. You may also choose to use such covered code | ||
under the terms of any subsequent version of the license | ||
published by the PHP Group. No one other than the PHP Group has | ||
the right to modify the terms applicable to covered code created | ||
under this License. | ||
|
||
6. Redistributions of any form whatsoever must retain the following | ||
acknowledgment: | ||
"This product includes PHP software, freely available from | ||
<http://www.php.net/software/>". | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND | ||
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP | ||
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
-------------------------------------------------------------------- | ||
|
||
This software consists of voluntary contributions made by many | ||
individuals on behalf of the PHP Group. | ||
|
||
The PHP Group can be contacted via Email at [email protected]. | ||
|
||
For more information on the PHP Group and the PHP project, | ||
please see <http://www.php.net>. | ||
|
||
PHP includes the Zend Engine, freely available at | ||
<http://www.zend.com>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# php-ext-arraylist | ||
|
||
[![Build Status](https://travis-ci.org/wxxiong6/php-ext-snowflake.svg?branch=master)](https://github.com/twitter-archive/snowflake) | ||
|
||
[Twitter SnowFlake](https://github.com/twitter-archive/snowflake, "Twitter SnowFlake") PHP扩展 | ||
|
||
## Requirement | ||
php-5.0 + | ||
|
||
## Install | ||
# Compile ArrayList in Linux mac | ||
|
||
```shell | ||
phpize | ||
./configure --enable-snowflake | ||
make | ||
make install | ||
``` | ||
|
||
## Document | ||
```php | ||
snowflake::getId(); | ||
//6613061356910543118 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
dnl $Id$ | ||
dnl config.m4 for extension snowflake | ||
|
||
dnl Comments in this file start with the string 'dnl'. | ||
dnl Remove where necessary. This file will not work | ||
dnl without editing. | ||
|
||
dnl If your extension references something external, use with: | ||
|
||
dnl PHP_ARG_WITH(snowflake, for snowflake support, | ||
dnl Make sure that the comment is aligned: | ||
dnl [ --with-snowflake Include snowflake support]) | ||
|
||
dnl Otherwise use enable: | ||
|
||
PHP_ARG_ENABLE(snowflake, whether to enable snowflake support, | ||
dnl Make sure that the comment is aligned: | ||
[ --enable-snowflake Enable snowflake support]) | ||
|
||
if test "$PHP_SNOWFLAKE" != "no"; then | ||
dnl Write more examples of tests here... | ||
|
||
dnl # get library FOO build options from pkg-config output | ||
dnl AC_PATH_PROG(PKG_CONFIG, pkg-config, no) | ||
dnl AC_MSG_CHECKING(for libfoo) | ||
dnl if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists foo; then | ||
dnl if $PKG_CONFIG foo --atleast-version 1.2.3; then | ||
dnl LIBFOO_CFLAGS=`$PKG_CONFIG foo --cflags` | ||
dnl LIBFOO_LIBDIR=`$PKG_CONFIG foo --libs` | ||
dnl LIBFOO_VERSON=`$PKG_CONFIG foo --modversion` | ||
dnl AC_MSG_RESULT(from pkgconfig: version $LIBFOO_VERSON) | ||
dnl else | ||
dnl AC_MSG_ERROR(system libfoo is too old: version 1.2.3 required) | ||
dnl fi | ||
dnl else | ||
dnl AC_MSG_ERROR(pkg-config not found) | ||
dnl fi | ||
dnl PHP_EVAL_LIBLINE($LIBFOO_LIBDIR, SNOWFLAKE_SHARED_LIBADD) | ||
dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS) | ||
|
||
dnl # --with-snowflake -> check with-path | ||
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this | ||
dnl SEARCH_FOR="/include/snowflake.h" # you most likely want to change this | ||
dnl if test -r $PHP_SNOWFLAKE/$SEARCH_FOR; then # path given as parameter | ||
dnl SNOWFLAKE_DIR=$PHP_SNOWFLAKE | ||
dnl else # search default path list | ||
dnl AC_MSG_CHECKING([for snowflake files in default path]) | ||
dnl for i in $SEARCH_PATH ; do | ||
dnl if test -r $i/$SEARCH_FOR; then | ||
dnl SNOWFLAKE_DIR=$i | ||
dnl AC_MSG_RESULT(found in $i) | ||
dnl fi | ||
dnl done | ||
dnl fi | ||
dnl | ||
dnl if test -z "$SNOWFLAKE_DIR"; then | ||
dnl AC_MSG_RESULT([not found]) | ||
dnl AC_MSG_ERROR([Please reinstall the snowflake distribution]) | ||
dnl fi | ||
|
||
dnl # --with-snowflake -> add include path | ||
dnl PHP_ADD_INCLUDE($SNOWFLAKE_DIR/include) | ||
|
||
dnl # --with-snowflake -> check for lib and symbol presence | ||
dnl LIBNAME=snowflake # you may want to change this | ||
dnl LIBSYMBOL=snowflake # you most likely want to change this | ||
|
||
dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, | ||
dnl [ | ||
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SNOWFLAKE_DIR/$PHP_LIBDIR, SNOWFLAKE_SHARED_LIBADD) | ||
dnl AC_DEFINE(HAVE_SNOWFLAKELIB,1,[ ]) | ||
dnl ],[ | ||
dnl AC_MSG_ERROR([wrong snowflake lib version or lib not found]) | ||
dnl ],[ | ||
dnl -L$SNOWFLAKE_DIR/$PHP_LIBDIR -lm | ||
dnl ]) | ||
dnl | ||
dnl PHP_SUBST(SNOWFLAKE_SHARED_LIBADD) | ||
|
||
PHP_NEW_EXTENSION(snowflake, snowflake.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// $Id$ | ||
// vim:ft=javascript | ||
|
||
// If your extension references something external, use ARG_WITH | ||
// ARG_WITH("snowflake", "for snowflake support", "no"); | ||
|
||
// Otherwise, use ARG_ENABLE | ||
ARG_ENABLE("snowflake", "enable snowflake support", "no"); | ||
|
||
if (PHP_SNOWFLAKE != "no") { | ||
EXTENSION("snowflake", "snowflake.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 7 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 1997-2018 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
/* $Id$ */ | ||
|
||
#ifndef PHP_SNOWFLAKE_H | ||
#define PHP_SNOWFLAKE_H | ||
|
||
extern zend_module_entry snowflake_module_entry; | ||
#define phpext_snowflake_ptr &snowflake_module_entry | ||
|
||
#define PHP_SNOWFLAKE_VERSION "0.1.0" /* Replace with version number for your extension */ | ||
|
||
#ifdef PHP_WIN32 | ||
# define PHP_SNOWFLAKE_API __declspec(dllexport) | ||
#elif defined(__GNUC__) && __GNUC__ >= 4 | ||
# define PHP_SNOWFLAKE_API __attribute__ ((visibility("default"))) | ||
#else | ||
# define PHP_SNOWFLAKE_API | ||
#endif | ||
|
||
#ifdef ZTS | ||
#include "TSRM.h" | ||
#endif | ||
|
||
/* Always refer to the globals in your function as SNOWFLAKE_G(variable). | ||
You are encouraged to rename these macros something shorter, see | ||
examples in any other php module directory. | ||
*/ | ||
// #define SNOWFLAKE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(snowflake, v) | ||
|
||
#if defined(ZTS) && defined(COMPILE_DL_SNOWFLAKE) | ||
ZEND_TSRMLS_CACHE_EXTERN() | ||
#endif | ||
|
||
#ifdef ZTS | ||
#define SF_G(v) TSRMG(sf_globals_id, zend_sf_globals *, v) | ||
#else | ||
#define SF_G(v) (snowflake_globals.v) | ||
#endif | ||
/* | ||
Declare any global variables you may need between the BEGIN | ||
and END macros here: | ||
*/ | ||
ZEND_BEGIN_MODULE_GLOBALS(snowflake) | ||
zend_long worker_id; | ||
zend_long region_id; | ||
zend_long epoch; | ||
zend_long region_bits; | ||
zend_long worker_bits; | ||
zend_long sequence_bits; | ||
zend_long time_bits; | ||
ZEND_END_MODULE_GLOBALS(snowflake) | ||
|
||
#define SNOWFLAKE_WORKER_ID "1" | ||
#define SNOWFLAKE_REGION_ID "1" | ||
#define SNOWFLAKE_EPOCH "1576080000000" //2019-12-12 | ||
#define SNOWFLAKE_TIME_BITS "41" | ||
#define SNOWFLAKE_REGIONID_BITS "4" | ||
#define SNOWFLAKE_WORKERID_BITS "10" | ||
#define SNOWFLAKE_SEQUENCE_BITS "8" | ||
typedef struct _snowflake_state snowflake; | ||
struct _snowflake_state { | ||
zend_long time; | ||
zend_long seq_max; | ||
zend_long worker_id; | ||
zend_long region_id; | ||
zend_long seq; | ||
zend_long time_bits; | ||
zend_long region_bits; | ||
zend_long worker_bits; | ||
}; | ||
|
||
static zend_long snowflake_id(snowflake *); | ||
static int snowflake_init(int region_id, int worker_id, snowflake *); | ||
|
||
|
||
#endif /* PHP_SNOWFLAKE_H */ | ||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
* vim600: noet sw=4 ts=4 fdm=marker | ||
* vim<600: noet sw=4 ts=4 | ||
*/ |
Oops, something went wrong.