-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add fsync() function #6650
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
Closed
Closed
Add fsync() function #6650
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
684a979
fsync initial
dwgebler 89e0c2f
fix warnings regarding stream_ops order
dwgebler f42d8bc
Implement fsync via set_option
dwgebler b8a54b1
fix typo on fflush condition
dwgebler 400e4ee
added basic tests
dwgebler 55ecd46
update test for warning format
dwgebler b8a2a29
fix test typo: missing new line causing test failure
dwgebler c4b7d5d
remove manual changes to generated arginfo
dwgebler 344f380
regenerated args header
dwgebler f63410c
improve implementation of fsync PHP function
dwgebler e018a8e
cleanup of stdiop fsync
dwgebler 994aa8c
fix ordering for gcc
dwgebler 8ada0d9
add fdatasync
dwgebler e7f8428
add ro tests and fdatasync tests
dwgebler 1f4cc8e
update tests; replace test fsync ro failure on posix
dwgebler a9b2ee5
replace spaced indent with tab
dwgebler 974a93d
Merge remote-tracking branch 'origin/master' into fsync-demo2
dwgebler 02739df
address review comments
dwgebler 80cbc29
remove unused variable
dwgebler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--TEST-- | ||
Test fdatasync() function: basic functionality | ||
--FILE-- | ||
<?php | ||
|
||
echo "*** Testing fdatasync(): writing to a file and reading the contents ***\n"; | ||
$data = <<<EOD | ||
first line of string | ||
second line of string | ||
third line of string | ||
EOD; | ||
|
||
$file_path = __DIR__; | ||
$filename = "$file_path/fdatasync_basic.tmp"; | ||
|
||
// opening a file | ||
$file_handle = fopen($filename, "w"); | ||
if($file_handle == false) | ||
exit("Error:failed to open file $filename"); | ||
|
||
if(substr(PHP_OS, 0, 3) == "WIN") { | ||
dwgebler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$data = str_replace("\r",'', $data); | ||
} | ||
|
||
// writing data to the file | ||
var_dump( fwrite($file_handle, $data) ); | ||
var_dump( fdatasync($file_handle) ); | ||
var_dump( readfile($filename) ); | ||
|
||
echo "\n*** Testing fdatasync(): for return type ***\n"; | ||
$return_value = fdatasync($file_handle); | ||
var_dump( is_bool($return_value) ); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Testing fdatasync(): attempting to sync stdin ***\n"; | ||
$file_handle = fopen("php://stdin", "w"); | ||
var_dump(fdatasync($file_handle)); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Testing fdatasync(): for non-file stream ***\n"; | ||
$file_handle = fopen("php://memory", "w"); | ||
$return_value = fdatasync($file_handle); | ||
var_dump( ($return_value) ); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Done ***"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$file_path = __DIR__; | ||
$filename = "$file_path/fdatasync_basic.tmp"; | ||
unlink($filename); | ||
?> | ||
--EXPECTF-- | ||
*** Testing fdatasync(): writing to a file and reading the contents *** | ||
int(63) | ||
bool(true) | ||
first line of string | ||
second line of string | ||
third line of stringint(63) | ||
|
||
*** Testing fdatasync(): for return type *** | ||
bool(true) | ||
|
||
*** Testing fdatasync(): attempting to sync stdin *** | ||
bool(false) | ||
|
||
*** Testing fdatasync(): for non-file stream *** | ||
|
||
Warning: fdatasync(): Can't fsync this stream! in %s on line %d | ||
bool(false) | ||
|
||
*** Done *** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--TEST-- | ||
Test fsync() function: basic functionality | ||
--FILE-- | ||
<?php | ||
|
||
echo "*** Testing fsync(): writing to a file and reading the contents ***\n"; | ||
$data = <<<EOD | ||
first line of string | ||
second line of string | ||
third line of string | ||
EOD; | ||
|
||
$file_path = __DIR__; | ||
$filename = "$file_path/fsync_basic.tmp"; | ||
|
||
// opening a file | ||
$file_handle = fopen($filename, "w"); | ||
if($file_handle == false) | ||
exit("Error:failed to open file $filename"); | ||
|
||
if(substr(PHP_OS, 0, 3) == "WIN") { | ||
$data = str_replace("\r",'', $data); | ||
} | ||
|
||
// writing data to the file | ||
var_dump( fwrite($file_handle, $data) ); | ||
var_dump( fsync($file_handle) ); | ||
var_dump( readfile($filename) ); | ||
|
||
echo "\n*** Testing fsync(): for return type ***\n"; | ||
$return_value = fsync($file_handle); | ||
var_dump( is_bool($return_value) ); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Testing fsync(): attempting to sync stdin ***\n"; | ||
$file_handle = fopen("php://stdin", "w"); | ||
var_dump(fsync($file_handle)); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Testing fsync(): for non-file stream ***\n"; | ||
$file_handle = fopen("php://memory", "w"); | ||
$return_value = fsync($file_handle); | ||
var_dump( ($return_value) ); | ||
fclose($file_handle); | ||
|
||
echo "\n*** Done ***"; | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$file_path = __DIR__; | ||
$filename = "$file_path/fsync_basic.tmp"; | ||
unlink($filename); | ||
?> | ||
--EXPECTF-- | ||
*** Testing fsync(): writing to a file and reading the contents *** | ||
int(63) | ||
bool(true) | ||
first line of string | ||
second line of string | ||
third line of stringint(63) | ||
|
||
*** Testing fsync(): for return type *** | ||
bool(true) | ||
|
||
*** Testing fsync(): attempting to sync stdin *** | ||
bool(false) | ||
|
||
*** Testing fsync(): for non-file stream *** | ||
|
||
Warning: fsync(): Can't fsync this stream! in %s on line %d | ||
bool(false) | ||
|
||
*** Done *** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.