Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PHP 7's Extension API #4

Open
meinemitternacht opened this issue Sep 12, 2017 · 15 comments
Open

Support PHP 7's Extension API #4

meinemitternacht opened this issue Sep 12, 2017 · 15 comments

Comments

@meinemitternacht
Copy link

Are there any plans to support PHP 7 with this wrapper? I am interested in integrating LMDB with an embedded device project, but cannot compile this against the PHP 7 headers.

@mpremus
Copy link
Owner

mpremus commented Sep 12, 2017 via email

@wkhayrattee
Copy link

hey @mpremus can you give me some hints or guidance as to how to proceed to try to make this lib php7 compatible?

@dana321
Copy link

dana321 commented Feb 11, 2018

@7php @meinemitternacht The latest php version 7.2 supports lmdb by compiling the dba extension with --with-lmdb=/path/to/lmdb

@dana321
Copy link

dana321 commented Feb 11, 2018

For example, with brew (homebrew/linuxbrew):
--- install brew and phpbrew first with php 7.2 ---

brew install lmdb
phpbrew ext install dba -- --with-lmdb=/usr/local/opt/lmdb

@meinemitternacht
Copy link
Author

@dana321 thank you! I'll give it a look at work tomorrow.

@wkhayrattee
Copy link

wkhayrattee commented Feb 11, 2018

@dana321 did you even tried running it on Ubuntu 16?
Get past all the automated stuffs like "brew", get on the commandline from A to Z.
If it works, can you post the exact steps you take, every single details, as it's not working on my end.

Also how can it be working when the Makefile is statically calling php5 ??
gcc -shared -fpic lmdb-php_wrap.c -I/usr/include/php5/Zend/ -I/usr/include/php5/ -I/usr/include/php5/TSRM/ -I/usr/include/php5/main/ -llmdb -o lmdb-php.so

Obviously it has to be something like:

$ gcc -shared `php-config --includes` -fpic -c lmdb-php_wrap.c -llmdb -o /path/to/lmdb-php.so

So my output with errors go something like:

lmdb-php_wrap.c:4478:50: error: macro "ZVAL_STRING" passed 3 arguments, but takes just 2
       ZVAL_STRING(return_value, (char *)result, 1);
                                                  ^
lmdb-php_wrap.c:4478:7: error: 'ZVAL_STRING' undeclared (first use in this function)
       ZVAL_STRING(return_value, (char *)result, 1);
       ^
In file included from /usr/include/php/20151012/Zend/zend.h:33:0,
                 from lmdb-php_wrap.c:706:
lmdb-php_wrap.c: In function '_wrap_destroy_p_f_p_q_const__struct_MDB_val_p_q_const__struct_MDB_val__int':
lmdb-php_wrap.c:4489:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_f_p_struct_MDB_val_p_void_p_void_p_void__void':
lmdb-php_wrap.c:4493:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_f_p_struct_MDB_env_p_q_const__char__void':
lmdb-php_wrap.c:4497:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_stat':
lmdb-php_wrap.c:4500:3: warning: implicit declaration of function '__wrap_delete_MDB_stat' [-Wimplicit-function-declaration]
   __wrap_delete_MDB_stat(rsrc, SWIGTYPE_p_MDB_stat->name TSRMLS_CC);
   ^
lmdb-php_wrap.c:4500:26: error: 'rsrc' undeclared (first use in this function)
   __wrap_delete_MDB_stat(rsrc, SWIGTYPE_p_MDB_stat->name TSRMLS_CC);
                          ^
In file included from /usr/include/php/20151012/Zend/zend.h:33:0,
                 from lmdb-php_wrap.c:706:
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_txn':
lmdb-php_wrap.c:4504:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_unsigned_int':
lmdb-php_wrap.c:4508:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_val':
lmdb-php_wrap.c:4511:3: warning: implicit declaration of function '__wrap_delete_MDB_val' [-Wimplicit-function-declaration]
   __wrap_delete_MDB_val(rsrc, SWIGTYPE_p_MDB_val->name TSRMLS_CC);
   ^
lmdb-php_wrap.c:4511:25: error: 'rsrc' undeclared (first use in this function)
   __wrap_delete_MDB_val(rsrc, SWIGTYPE_p_MDB_val->name TSRMLS_CC);
                         ^
In file included from /usr/include/php/20151012/Zend/zend.h:33:0,
                 from lmdb-php_wrap.c:706:
lmdb-php_wrap.c: In function '_wrap_destroy_p_mode_t':
lmdb-php_wrap.c:4515:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_void':
lmdb-php_wrap.c:4519:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_p_void':
lmdb-php_wrap.c:4523:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_env':
lmdb-php_wrap.c:4527:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_char':
lmdb-php_wrap.c:4531:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_cursor':
lmdb-php_wrap.c:4535:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_cursor_op':
lmdb-php_wrap.c:4539:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_MDB_envinfo':
lmdb-php_wrap.c:4542:3: warning: implicit declaration of function '__wrap_delete_MDB_envinfo' [-Wimplicit-function-declaration]
   __wrap_delete_MDB_envinfo(rsrc, SWIGTYPE_p_MDB_envinfo->name TSRMLS_CC);
   ^
lmdb-php_wrap.c:4542:29: error: 'rsrc' undeclared (first use in this function)
   __wrap_delete_MDB_envinfo(rsrc, SWIGTYPE_p_MDB_envinfo->name TSRMLS_CC);
                             ^
In file included from /usr/include/php/20151012/Zend/zend.h:33:0,
                 from lmdb-php_wrap.c:706:
lmdb-php_wrap.c: In function '_wrap_destroy_p_f_p_q_const__char_p_void__int':
lmdb-php_wrap.c:4546:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_int':
lmdb-php_wrap.c:4550:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
                                  ^
lmdb-php_wrap.c: In function '_wrap_destroy_p_int':
lmdb-php_wrap.c:4554:9: error: 'rsrc' undeclared (first use in this function)
   efree(rsrc->ptr);
         ^
/usr/include/php/20151012/Zend/zend_alloc.h:163:34: note: in definition of macro 'efree'
 #define efree(ptr)       _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

/c @meinemitternacht

@dana321
Copy link

dana321 commented Feb 11, 2018

@7php Its clear you have no idea what you're doing or what you're talking about - thats ok.

But don't make demands of me, i provided the solution and you're still trying to compile the old php module against the php5 header files. I am under no obligation to help you whatsoever!

Theres a reason why people use and learn linuxbrew and phpbrew, its because you can compile the latest and greatest software without the hastle. Take the hint.

@meinemitternacht
Copy link
Author

@7php
http://php.net/manual/en/migration72.other-changes.php

The DBA extension natively supports LMDB now, no need for a wrapper.

@wkhayrattee
Copy link

@meinemitternacht that was very helpful and it's a great news as I really wanted to use LMDB on a project close to my heart.
Thank you sooo much for this info, precious!

cheers

@saippuakauppias
Copy link

phpbrew is bad tool (valet not worked with this).

Method for configure and build from sources PHP7 in homebrew: https://gist.github.com/saippuakauppias/fac2a33dfe420adb4a6cf19c257eef46

@mpremus
Copy link
Owner

mpremus commented Oct 30, 2019 via email

@meinemitternacht
Copy link
Author

@saippuakauppias is there a reason you would not want to use the DBA extension that is bundled with PHP?

@saippuakauppias
Copy link

saippuakauppias commented Oct 31, 2019

Because by default php builts without lmdb support (see docs). DBA extension enabled by default, but without lmdb (need reconfigure php before compiling).

@wkhayrattee
Copy link

wkhayrattee commented Jan 16, 2022

Wow, I cannot believe it's already Jan 2022, so many years later I got back to this :) Hope everyone in here is safe and doing well.

@dana321 I read my comments above and I am not proud of what I wrote up there. That year was one of my worse period in rl, and I clearly see I also completely misunderstood your reply as well at that time.

I'm sorry for my tone and way of speaking there - not the proper me. irrespective of my situation, I should have done much better in replying. Please accept my sincere apology.


@saippuakauppias I actually came here to get in touch with you since I could not find a point of contact with you.

I am hitting MDB_MAP_FULL with LMDB using php_dba and I saw your gist here aimed at MAC.

I also found someone's interaction on the php mail list here.
The php-src test as well.

The limit of 1MB seems still in place and I keep hitting the issue despite passing the 4th param as 'map_size=1048576000' since as per the mail list that 4th param is passed as a string to the underlying driver.

Have you been able to find any solution for Ubuntu servers or your case was on Mac only? Because of this issue, I'll probably drop usage for LMDB, which is sad due the power it has.

@saippuakauppias
Copy link

On Ubuntu, I just build LMDB and PHP myself and bypass this restriction (I've been using it in production for over a year):

set -euo pipefail

# install lmdb
apt -y install make gcc wget
cd ~
    # clone
LMDB_VERSION="0.9.24"
wget https://github.com/LMDB/lmdb/archive/LMDB_${LMDB_VERSION}.tar.gz

tar -zxvf LMDB_${LMDB_VERSION}.tar.gz

cd ~/lmdb-LMDB_${LMDB_VERSION}/libraries/liblmdb/
    # patch 1
# get memory pagesize: `getconf PAGESIZE`
# 4194304000 Bytes = 4GB
sed -e "s/DEFAULT_MAPSIZE\s1048576/DEFAULT_MAPSIZE 4194304000/g" ~/lmdb-LMDB_${LMDB_VERSION}/libraries/liblmdb/mdb.c -i
LMDB_MAPSIZE_CHECK=`cat ~/lmdb-LMDB_${LMDB_VERSION}/libraries/liblmdb/mdb.c | grep '4194304000' | wc -l`
echo "LMDB_MAPSIZE_CHECK: ${LMDB_MAPSIZE_CHECK}"

    # patch 2
sed -e "s/DEFAULT_READERS\s126/DEFAULT_READERS 1024/g" ~/lmdb-LMDB_${LMDB_VERSION}/libraries/liblmdb/mdb.c -i
LMDB_READERS_CHECK=`cat ~/lmdb-LMDB_${LMDB_VERSION}/libraries/liblmdb/mdb.c | grep 'DEFAULT_READERS 1024' | wc -l`
echo "LMDB_READERS_CHECK: ${LMDB_READERS_CHECK}"

    # install
make
make test
make install prefix=/opt/lmdb # directory path: https://ru.wikipedia.org/wiki/FHS

# install PHP
# like: https://gist.github.com/saippuakauppias/d3e2cdd1c654313efefef3b8b66a5802
# with :
PHP_CONFIGURE_ARGS="--prefix=/usr/local/php7 \
# ...
  --enable-dba \
  --with-lmdb=/opt/lmdb \
"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants