cvs: pear /Net_GeoIP GeoIP.php
| From: | Hans Lellelid | Date: | Mon, 30 Oct 2006 13:49:38 +0000 |
| Subject: | cvs: pear /Net_GeoIP GeoIP.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42889@lists.php.net to get a copy of this message | ||
hlellelid Mon Oct 30 13:49:38 2006 UTC
Modified files:
/pear/Net_GeoIP GeoIP.php
Log:
Added patch from Gyuchang Jun to use smaller buffers when loading data into shared memory. This
gets around issue with standard PHP installs running out of available memory when using larger
databases.
http://cvs.php.net/viewvc.cgi/pear/Net_GeoIP/GeoIP.php?r1=1.3&r2=1.4&diff_format=u
Index: pear/Net_GeoIP/GeoIP.php
diff -u pear/Net_GeoIP/GeoIP.php:1.3 pear/Net_GeoIP/GeoIP.php:1.4
--- pear/Net_GeoIP/GeoIP.php:1.3 Wed Jun 7 16:34:25 2006
+++ pear/Net_GeoIP/GeoIP.php Mon Oct 30 13:49:38 2006
@@ -24,7 +24,7 @@
// | Hans Lellelid <hans@xmpl.org> |
// +----------------------------------------------------------------------+
//
-// $Id: GeoIP.php,v 1.3 2006/06/07 16:34:25 hlellelid Exp $
+// $Id: GeoIP.php,v 1.4 2006/10/30 13:49:38 hlellelid Exp $
/**
* GeoIP class provides an API for performing geo-location lookups based on IP
@@ -119,7 +119,7 @@
*
* @author Jim Winstead <jimw@apache.org> (original Maxmind PHP API)
* @author Hans Lellelid <hans@xmpl.org>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @package Net_GeoIP
*/
class Net_GeoIP
@@ -414,13 +414,21 @@
$s_array = fstat($fp);
$size = $s_array['size'];
- if ($shmid = shmop_open(self::SHM_KEY, "w", 0, 0)) {
+ if ($shmid = @shmop_open(self::SHM_KEY, "w", 0, 0)) {
shmop_delete ($shmid);
shmop_close ($shmid);
}
- $shmid = shmop_open(self::SHM_KEY, "c", 0644, $size);
- shmop_write($shmid, fread($fp, $size), 0);
- shmop_close($shmid);
+
+ if ($shmid = @shmop_open(self::SHM_KEY, "c", 0644, $size)) {
+ $offset = 0;
+ while ($offset < $size) {
+ $buf = fread($fp, 524288);
+ shmop_write($shmid, $buf, $offset);
+ $offset += 524288;
+ }
+ shmop_close($shmid);
+ }
+
fclose($fp);
}