stat["blocks"] returns -1

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

stat["blocks"] returns -1

Post 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
 
 
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: stat["blocks"] returns -1

Post 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)
There are 10 types of people in this world, those who understand binary and those who don't
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

Re: stat["blocks"] returns -1

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: stat["blocks"] returns -1

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
dml
Forum Contributor
Posts: 133
Joined: Sat Jan 26, 2008 2:20 pm

Re: stat["blocks"] returns -1

Post 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
Post Reply