Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filesize() to return size of symlink rather than the target file size #3598

Open
RV7PR opened this issue Jul 10, 2024 · 13 comments
Open

filesize() to return size of symlink rather than the target file size #3598

RV7PR opened this issue Jul 10, 2024 · 13 comments
Labels
bug Documentation contains incorrect information

Comments

@RV7PR
Copy link

RV7PR commented Jul 10, 2024

Description

filesize() returns false on symlink with warning: filesize(): stat failed for {filename}
I have to use lstat($symlink)['size'] to get size of a symlink

PHP Version

PHP 8.3.8

Operating System

CentOS Stream release 9


Edit by @cmb69: see #3598 (comment) for the latest suggestion to improve the documentation.

@RV7PR RV7PR added bug Documentation contains incorrect information Status: Needs Triage labels Jul 10, 2024
@devnexen
Copy link
Member

I cannot reproduce with php 8.3.6 nor with 8.3.8, would you have a reproducer or give more details regarding your case ?

@RV7PR
Copy link
Author

RV7PR commented Jul 11, 2024

I also have this issue on another server with centos 7 and php 8.3.8.
It's just a symlink created using symlink() that I want to delete after I get the size.

@devnexen
Copy link
Member

There might be more to it. e.g. are you getting a symlink from a shared (virtualised ?) folder ? network mountpoint ?

@RV7PR
Copy link
Author

RV7PR commented Jul 11, 2024

Nope it's a symlink to a file in the same folder.
But it might be that the target file is deleted before the symlink itself.

@devnexen
Copy link
Member

It might thus

would you have a reproducer or give more details regarding your case ?

@RV7PR
Copy link
Author

RV7PR commented Jul 11, 2024

$file = tempnam(sys_get_temp_dir(), '');
$symlink = $file . '.symlink';
symlink('./' . basename($file), $symlink);
unlink($file);
var_dump(filesize($symlink));

@devnexen
Copy link
Member

sure ... looking at php_stat, it seems to behave "as expected', now I m torn between bug and "feature request to change longtime behavior".

@RV7PR
Copy link
Author

RV7PR commented Jul 11, 2024

Yeah I didn't expect it to behave like this, I thought filesize would show size of the file supplied and not the target file of a symlink, would've made more sense to do filesize(realpath()) if target file size was needed🤔

Well probably because in most cases filesize of a symlink would be irrelevant😅

@bukka
Copy link
Member

bukka commented Jul 21, 2024

I don't think we can change this. I would not consider it as a bug. This would require RFC to get changed.

@bukka bukka added Feature and removed bug Documentation contains incorrect information Status: Needs Triage labels Jul 21, 2024
@bukka bukka changed the title filesize() returns false on symlink filesize() to return size of symlink rather that target file size Jul 21, 2024
@bukka bukka changed the title filesize() to return size of symlink rather that target file size filesize() to return size of symlink rather than the target file size Jul 21, 2024
@cmb69
Copy link
Member

cmb69 commented Jul 23, 2024

@RV7PR, are you interested in pursuing the RFC process?

@RV7PR
Copy link
Author

RV7PR commented Jul 23, 2024

@cmb69 Not really... maybe we should just add a note for filesize() and SplFileInfo::getSize() specifiying that it always uses the target file of a symlink and if the filesize is needed for a symlink that lstat()['size'] should be used and that if target file does not exists anymore it generates a warning.

@cmb69
Copy link
Member

cmb69 commented Jul 23, 2024

Well, I'm fine with transferring this to doc-en (so the documentation could be updated). Any objections?

@RV7PR
Copy link
Author

RV7PR commented Jul 23, 2024

I'm okay with that

@cmb69 cmb69 transferred this issue from php/php-src Jul 23, 2024
@Girgias Girgias added the bug Documentation contains incorrect information label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Documentation contains incorrect information
Projects
None yet
Development

No branches or pull requests

5 participants