Page 1 of 1

stat["blocks"] returns -1

Posted: Sat Jan 26, 2008 2:29 pm
by dml
Hi, any reason why the "blksize" and "blocks" elements returned by stat() should be -1? Just curious.

Code: Select all

 
> stat testfile
  File: `testfile'
  Size: 223             Blocks: 8          IO Block: 4096   regular file
 
> php -r '$s = stat("testfile");var_dump($s["blocks"]);'
int(-1)
 
> php --version
PHP 5.2.0-8+etch9 (cli) (built: Dec 29 2007 03:30:27) 
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
 
 

Re: stat["blocks"] returns -1

Posted: Sat Jan 26, 2008 2:42 pm
by VladSun
Hm ...
Only valid on systems supporting the st_blksize type - other systems (e.g. Windows) return -1.
Weird ...

I have no problems with this:
~# php --version
PHP 5.2.4 (cli) (built: Oct 27 2007 19:25:27)

~# stat 1.txt
File: `1.txt'
Size: 13389 Blocks: 32 IO Block: 131072 regular file
~# php -r '$s = stat("1.txt");var_dump($s["blocks"]);'
int(32)

Re: stat["blocks"] returns -1

Posted: Sat Jan 26, 2008 3:08 pm
by dml
Yeah, I was wondering about that st_blksize thing. I don't know what it is, nor how to confirm whether my (Linux) system supports it. Nevertheless, it seems strange that PHP compiled for Linux can't just make the system call to get the information.

Re: stat["blocks"] returns -1

Posted: Sat Jan 26, 2008 4:00 pm
by VladSun
Just tried it with:

Code: Select all

php --version
PHP 5.2.0-8+etch10 (cli) (built: Jan 18 2008 18:52:58)
 
The same result as yours:

Code: Select all

 ["blksize"]=>
  int(-1)
  ["blocks"]=>
  int(-1)
 
I don't know what's hapenning... Maybe this is a fixed PHP5 CLI bug in later versions.

Re: stat["blocks"] returns -1

Posted: Sat Jan 26, 2008 4:58 pm
by dml
Thanks for trying that out. Good to know it's not something weird with the way I've set up my system. :D