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

If php source is invoked when it's being created, HHVM will lost the complete code. #1447

Closed
wwbmmm opened this issue Dec 27, 2013 · 6 comments · May be fixed by #7926
Closed

If php source is invoked when it's being created, HHVM will lost the complete code. #1447

wwbmmm opened this issue Dec 27, 2013 · 6 comments · May be fixed by #7926

Comments

@wwbmmm
Copy link
Contributor

wwbmmm commented Dec 27, 2013

code to reproduce:

$ cat test.php

<?php
$file = 'code.php';
$fd = fopen($file, 'w+');
fwrite($fd, "<?php\n");
echo "Include when file is incomplete\n";
include($file);
fwrite($fd, "var_dump('Hello World');\n");
fclose($fd);

sleep(1); // sleep enough time for file reload

echo "Include when file is complete\n";
include($file);

$ hhvm test.php

Include when file is incomplete
Include when file is complete

$ rm code.php
$ php test.php

Include when file is incomplete
Include when file is complete
string(11) "Hello World"

When request this test.php in server mode, and then request code.php, you will get an empty response even after a long time, until code.php is modified or hhvm is restarted.

This may happen in actual scene online. For example, there is file a.php at the beginning and do the whole work. After some updates, file b.php is added and included in file a.php . During the online deployment, file a.php is modified first. When file b.php is being created, a request come up and invoke file a.php, that cause HHVM to parse and invoke the incomplete file b.php. After b.php is written completely, HHVM will not reload this file, so the incomplete b.php is always being used.

@scannell
Copy link
Contributor

Thanks for reporting this.

inotify notifications should take care of invalidating old units on Linux when files are modified. Are you running on Linux? (Are your source files on NFS where inotify is unsupported by any chance?)

@scannell
Copy link
Contributor

I'm still not clear on the scenario here.

@lokeshhctm: Files are being modified while they are loaded? We definitely don't actively test that scenario.

@SiebelsTim
Copy link
Contributor

I can reproduce this running on Ubuntu 14.04.
When you include a file twice it doesn't reload the file, instead it loads the contents from its previous include.
Maybe a caching problem?

Wishlist doesn't fit really, its a phpincompatibility

@paulbiss
Copy link
Contributor

cc @AlphaStream

@wwbmmm
Copy link
Contributor Author

wwbmmm commented Jul 24, 2017

This bug occurs when file system is ext2. It doesn't occur when file system is ext4. Because ext4 file system has higher file stat time resolution.

@lexidor
Copy link
Collaborator

lexidor commented Sep 16, 2022

I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.

In hhvm 4.67 and above, it is not possible to include a file multiple times.
https://hhvm.com/blog/2020/07/20/hhvm-4.67.html
This version of hhvm removed support for top-level code / pseudo-mains. (Code which lives outside a function and executes upon inclusion.)

The only constructs that may appear at the top-level are named entities (classes, constants, functions, types, enums, interfaces). If included more than once, this will throw an \Error or a fatal error: depending on your configuration.

So in order to include a file more than once, it must have been empty (with the exception of comments / whitespace). If it weren't empty, this would error out on the second include.

@lexidor lexidor closed this as completed Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants