maptiler/tileserver-php

Old 32bit systems and large .mbtiles > 2GB

EWindfield opened this issue · 3 comments

I'm having an issue when I opening mbtile that is more than 2GB. It produced 404 error on [host]/tileserver.php?/index.json?/[map]/...
I have no problem opening other smaller mbtile, do I need to set anything on php.ini or httpd.conf for it to load big mbtile?

Btw, I can opening the mbtile file with MapTiler

I found the issue to be the php5 filesize limit on 32-bit system. (>_< dont ask me why I'm still using 32-bit)
Particularly affecting the php function filemtime and is_file at function isDBLayer and function isModified of tileserver.php.

From php manual:

Note: Because PHP’s integer type is signed and many platforms use 32bit integers, filesize() ** may return unexpected results for files which are larger than **2GB. For files between 2GB and 4GB in size this can usually be overcome by using sprintf(“%u”, filesize($file)).

More info: http://php.net/manual/en/function.is-file.php

Changes I made:

function isModified($filename)
Replace
$lastModifiedTime = filemtime($filename);
With
$stat = explode('.', exec("stat -c%y {$filename}"));
$lastModifiedTime = strtotime($stat[0]);

function isDBLayer($layer)
Add new function
public function is_file_lfs($path){
exec('[ -f "'.$path.'" ]', $tmp, $ret);
return $ret == 0;
}
Replace
if (is_file($filename))
With
$filename = $this->config['dataRoot'] . $layer . '.mbtiles';
if ($this->is_file_lfs($filename))

Thanks for the report and suggested solution.

It seems like this is a problem of the setup of your web-hosting or server, when an upgrade could , instead of hacking the code.

Your suggested workaround may help others, but we will not merge it into master.
Calling exec("stat") and exec(-f) will for sure break compatibility with other platforms (such as PHP on Windows)

BTW you clearly have not used .htaccess file during installation - as the URLs contain tileserver.php.

Thanks for the reply and reminder on the .htaccess file.

Will proceed to upload all the files.