Ванька ([info]dedm) wrote,
@ 2009-04-08 19:11:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:development

Symlinks & php feature
Обнаружил интересную особенность при работе с симлинками, пока воспроизвел только в php: если по ходу выполнения скрипта меняется симлинк, то fopen его не подхватывает, и работает со ссылкой на старый файл. Примечтаельно, что аналогичные инструкции на C работают, как и ожидалось. Код под катом.

UPD: проблема решена, нужно использовать clearstatcache().



$ mkdir dir1 dir2; echo null1 > dir1/file; echo null2 >dir2/file
$ php -r " system('rm -f link');
system('ln -s dir1 link');

echo readlink('./link').PHP_EOL;

file_put_contents('./link/file', 'line1'.PHP_EOL);

system('rm -f link');
system('ln -s dir2 link');

echo readlink('./link').PHP_EOL;

file_put_contents('./link/file', 'line2'.PHP_EOL);
"
dir1
dir2
$
$ cat dir1/file ; cat dir2/file
line2
null2


А ожидаем:

line1
line2


UPD: Код на C, который приводит к ожидаемому результату:


int main()
{
int fd;

system("rm -f link");
system("ln -s dir1 link");

fd = fopen("./link/file", "wb");
fputs("line1\n", fd);
fclose(fd);

system("rm -f link");
system("ln -s dir2 link");

fd = fopen("./link/file", "wb");
fputs("line2\n", fd);
fclose(fd);


return 0;
}




(6 comments) - (Post a new comment)


[info]tishetsky
2009-04-08 04:54 pm UTC (link)
а если сустем() заменить на встроенный symlink/unlink?

(Reply to this) (Thread)


[info]dedm
2009-04-09 09:33 am UTC (link)
в этом все и дело.

system показывает, что операции происходят в контексте другого процесса, который может исполнятся параллельно.

(Reply to this) (Parent)(Thread)


[info]tishetsky
2009-04-09 11:45 am UTC (link)
дак понятно, что другого, он на то и сустем

можно подумать, что в сях аналогичная конструкция будет как-то по-другому работать

(Reply to this) (Parent)(Thread)


[info]dedm
2009-04-09 01:11 pm UTC (link)
представь себе, вот этот код приводит к ожидаемому результату, в отличие от php:


int main()
{
int fd;

system("rm -f link");
system("ln -s dir1 link");

fd = fopen("./link/file", "wb");
fputs("line1\n", fd);
fclose(fd);

system("rm -f link");
system("ln -s dir2 link");

fd = fopen("./link/file", "wb");
fputs("line2\n", fd);
fclose(fd);


return 0;
}

(Reply to this) (Parent)


[info]dedm
2009-04-09 02:55 pm UTC (link)
в общем, проблема решена, clearstatcache() is my friend.

(Reply to this) (Parent)

Want to download XRumer 5.0 for free!
(Anonymous)
2009-05-04 01:17 pm UTC (link)
Well!! I want to get software pack XRUMER 5.0 Palladium for free. Any download link?
I'm so need this magic program! It's can break captchas automatically! Activate accounts via email automatically too! Absolutely great software! Help me!
And did you hear news - price for XRumer 5.0 Palladium will grow up to $540 after 15 may 2009... And XRumer 2.9 and 3.0 - too old versions, it's cant break modern catpchas and cant break modern anti-bot protections. But XRumer 5.0 Palladium CAN!!!!
So help me for download this great soft for free! Thanks!

(Reply to this)


(6 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…