Skip to content

Commit ed9f424

Browse files
committed
try to improve the graceful fix in 1.0.3
- only lock libvips if we're running inside apache - use the sapi error logger for the warning message - include the binary API version in the .soname also, the notes section at the top of package.xml should repeat the most recent changelog notes see libvips/php-vips#27 libvips/php-vips#28
1 parent d5e34e8 commit ed9f424

File tree

8 files changed

+114
-21
lines changed

8 files changed

+114
-21
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
vips extension changelog
22

3+
Version 1.0.4 (2016-12-30)
4+
* Improve graceful fix from 1.0.3, see https://github.com/jcupitt/php-vips/issues/27
5+
* Better notes section in package.xml, see https://github.com/jcupitt/php-vips/issues/28
6+
37
Version 1.0.3 (2016-12-27)
48
--------------------------
59
* Lower min vips version to 8.2, see #4

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ libvips website, or build your own.
9191
$ pear package
9292
```
9393

94-
to make `vips-1.0.3.tgz`.
94+
to make `vips-1.0.4.tgz`.
9595

9696
To install by hand:
9797

File renamed without changes.

config.h.in~

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* config.h.in. Generated from configure.in by autoheader. */
2+
3+
/* Whether to build vips as dynamic module */
4+
#undef COMPILE_DL_VIPS
5+
6+
/* Define to 1 if you have the <dlfcn.h> header file. */
7+
#undef HAVE_DLFCN_H
8+
9+
/* Define to 1 if you have the <inttypes.h> header file. */
10+
#undef HAVE_INTTYPES_H
11+
12+
/* Define to 1 if you have the <memory.h> header file. */
13+
#undef HAVE_MEMORY_H
14+
15+
/* Define to 1 if you have the <stdint.h> header file. */
16+
#undef HAVE_STDINT_H
17+
18+
/* Define to 1 if you have the <stdlib.h> header file. */
19+
#undef HAVE_STDLIB_H
20+
21+
/* Define to 1 if you have the <strings.h> header file. */
22+
#undef HAVE_STRINGS_H
23+
24+
/* Define to 1 if you have the <string.h> header file. */
25+
#undef HAVE_STRING_H
26+
27+
/* Define to 1 if you have the <sys/stat.h> header file. */
28+
#undef HAVE_SYS_STAT_H
29+
30+
/* Define to 1 if you have the <sys/types.h> header file. */
31+
#undef HAVE_SYS_TYPES_H
32+
33+
/* Define to 1 if you have the <unistd.h> header file. */
34+
#undef HAVE_UNISTD_H
35+
36+
/* Whether you have vips */
37+
#undef HAVE_VIPS
38+
39+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
40+
#undef LT_OBJDIR
41+
42+
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
43+
#undef NO_MINUS_C_MINUS_O
44+
45+
/* Define to the address where bug reports for this package should be sent. */
46+
#undef PACKAGE_BUGREPORT
47+
48+
/* Define to the full name of this package. */
49+
#undef PACKAGE_NAME
50+
51+
/* Define to the full name and version of this package. */
52+
#undef PACKAGE_STRING
53+
54+
/* Define to the one symbol short name of this package. */
55+
#undef PACKAGE_TARNAME
56+
57+
/* Define to the home page for this package. */
58+
#undef PACKAGE_URL
59+
60+
/* Define to the version of this package. */
61+
#undef PACKAGE_VERSION
62+
63+
/* Define to 1 if you have the ANSI C header files. */
64+
#undef STDC_HEADERS

package.xml

+15-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
1515
<email>jcupitt@php.net</email>
1616
<active>yes</active>
1717
</lead>
18-
<date>2016-12-27</date>
18+
<date>2016-12-30</date>
1919
<version>
20-
<release>1.0.3</release>
20+
<release>1.0.4</release>
2121
<api>1.0.0</api>
2222
</version>
2323
<stability>
@@ -26,15 +26,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license filesource="LICENSE.txt">MIT</license>
2828
<notes>
29-
- First stable release.
29+
* Improve graceful fix from 1.0.3, see https://github.com/jcupitt/php-vips/issues/27
30+
* Better notes section in package.xml, see https://github.com/jcupitt/php-vips/issues/28
3031
</notes>
3132
<contents>
3233
<dir name="/">
3334
<file role='doc' name='API-1.0.0'/>
3435
<file role='doc' name='CREDITS'/>
3536
<file role='doc' name='LICENSE.txt'/>
3637
<file role='doc' name='README.md'/>
37-
<file role='doc' name='RELEASE-1.0.3'/>
38+
<file role='doc' name='RELEASE-1.0.4'/>
3839
<file role='doc' name='ChangeLog'/>
3940

4041
<file role='src' name='config.m4'/>
@@ -89,6 +90,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
8990
</extsrcrelease>
9091
<changelog>
9192

93+
<release>
94+
<stability><release>stable</release><api>stable</api></stability>
95+
<version><release>1.0.4</release><api>1.0.0</api></version>
96+
<date>2016-12-30</date>
97+
<notes>
98+
* Improve graceful fix from 1.0.3, see https://github.com/jcupitt/php-vips/issues/27
99+
* Better notes section in package.xml, see https://github.com/jcupitt/php-vips/issues/28
100+
</notes>
101+
</release>
102+
92103
<release>
93104
<stability><release>stable</release><api>stable</api></stability>
94105
<version><release>1.0.3</release><api>1.0.0</api></version>

php_vips.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extern zend_module_entry vips_module_entry;
66
#define phpext_vips_ptr &vips_module_entry
77

8-
#define PHP_VIPS_VERSION "1.0.3"
8+
#define PHP_VIPS_VERSION "1.0.4"
99

1010
#ifdef PHP_WIN32
1111
# define PHP_VIPS_API __declspec(dllexport)

vips-1.0.4.tgz

542 KB
Binary file not shown.

vips.c

+29-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "php.h"
1414
#include "php_ini.h"
1515
#include "ext/standard/info.h"
16+
#include "SAPI.h"
1617
#include "php_vips.h"
1718

1819
#include <vips/vips.h>
@@ -1621,21 +1622,34 @@ static void php_free_gobject(zend_resource *rsrc)
16211622
*/
16221623
PHP_MINIT_FUNCTION(vips)
16231624
{
1624-
/* "apachectl graceful" can cause us terrible problems. Within the main
1625-
* apache process, it will unload this extension, which in turn will unload
1626-
* libvips, since we are the only thing that references it, then reload
1627-
* again.
1628-
*
1629-
* Unfortunately, glib, which libvips uses, will often NOT get unloaded.
1630-
* When libvips then tries to init again, it'll find left-over types like
1631-
* VipsObject still registered in the system, and chaos will follow.
1632-
*
1633-
* A simple fix that will always work is just to lock libvips in memory and
1634-
* prevent unload.
1635-
*/
1636-
if (!dlopen("libvips.so", RTLD_LAZY | RTLD_NODELETE)) {
1637-
printf("php-vips-ext: unable to lock libvips -- "
1638-
"graceful may be unreliable\n");
1625+
if (strcmp(sapi_module.name, "apache2handler") == 0) {
1626+
/* "apachectl graceful" can cause us terrible problems. What happens:
1627+
*
1628+
* - the main apache process unloads this extension, vips.so
1629+
* - in turn, the C runtime will unload libvips.so, the vips library,
1630+
* since vips.so is the only thing that references it
1631+
* - libvips.so in turn uses glib.so, but this is often not unloaded,
1632+
* since other parts of apache can be using it (glib could also
1633+
* possibly be preventing unload itself, I'm not sure)
1634+
* - the main apache process then reloads vips.so, which in turn will
1635+
* reload libvips.so as it starts up
1636+
* - vips.so tries to init libvips.so
1637+
* - libvips.so tries to register its types (such as VipsImage) with
1638+
* glib.so, but finds the types from the previous init still there
1639+
* - everything breaks
1640+
*
1641+
* A simple fix that will always work is just to lock libvips in
1642+
* memory and prevent unload. We intentionally leak refs to the shared
1643+
* library.
1644+
*
1645+
* We include the binary API version number that this extension needs.
1646+
* We can't just load .so, that's only installed with libvips-dev,
1647+
* which may not be present at runtime.
1648+
*/
1649+
if (!dlopen("libvips.so.42", RTLD_LAZY | RTLD_NODELETE)) {
1650+
sapi_module.sapi_error(E_WARNING, "php-vips-ext: unable to lock "
1651+
"libvips -- graceful may be unreliable");
1652+
}
16391653
}
16401654

16411655
/* If you have INI entries, uncomment these lines

0 commit comments

Comments
 (0)