File tree Expand file tree Collapse file tree 7 files changed +8
-32
lines changed Expand file tree Collapse file tree 7 files changed +8
-32
lines changed Original file line number Diff line number Diff line change @@ -54,10 +54,7 @@ A very simple example task to write Hello World to a file:
5454// define the task...
5555$target = "document.txt";
5656$task = new AsyncTask(function () use ($target) {
57- $fp = fopen($target, "w");
58- fwrite($fp, "Hello World!!");
59- fflush($fp);
60- fclose($fp);
57+ file_put_contents($target, "Hello World!");
6158});
6259
6360// if you are using interfaces, then it is just like this:
Original file line number Diff line number Diff line change @@ -21,10 +21,7 @@ public function testCanRunClosure()
2121 $ testFileName = $ this ->getStoragePath ("testClosure.txt " );
2222 $ message = "Hello world! " ;
2323 $ task = new AsyncTask (function () use ($ testFileName , $ message ) {
24- $ fp = fopen ($ testFileName , "w " );
25- fwrite ($ fp , $ message );
26- fflush ($ fp );
27- fclose ($ fp );
24+ file_put_contents ($ testFileName , $ message );
2825 });
2926 $ task ->run ();
3027
@@ -85,10 +82,7 @@ public function testAsyncBasic()
8582 @unlink ($ testFileName );
8683 $ message = "Hello world! " ;
8784 $ task = new AsyncTask (function () use ($ testFileName , $ message ) {
88- $ fp = fopen ($ testFileName , "w " );
89- fwrite ($ fp , $ message );
90- fflush ($ fp );
91- fclose ($ fp );
85+ file_put_contents ($ testFileName , $ message );
9286 });
9387 $ task ->start ();
9488
Original file line number Diff line number Diff line change @@ -16,10 +16,7 @@ public function __construct(
1616
1717 public function execute (): void
1818 {
19- $ fp = fopen ($ this ->targetFilePath , "w " );
20- fwrite ($ fp , $ this ->message );
21- fflush ($ fp );
22- fclose ($ fp );
19+ file_put_contents ($ this ->targetFilePath , $ this ->message );
2320 }
2421
2522 public function handleTimeout (): void
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ public function execute(): void
2222
2323 public function handleTimeout (): void
2424 {
25- $ fp = fopen ($ this ->targetFilePath , "w " );
26- fwrite ($ fp , $ this ->message );
27- fflush ($ fp );
28- fclose ($ fp );
25+ file_put_contents ($ this ->targetFilePath , $ this ->message );
2926 }
3027}
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ public function execute(): void
2222
2323 public function handleTimeout (): void
2424 {
25- $ fp = fopen ($ this ->targetFilePath , "w " );
26- fwrite ($ fp , $ this ->message );
27- fflush ($ fp );
28- fclose ($ fp );
25+ file_put_contents ($ this ->targetFilePath , $ this ->message );
2926 }
3027}
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ public function execute(): void
2222
2323 public function handleTimeout (): void
2424 {
25- $ fp = fopen ($ this ->targetFilePath , "w " );
26- fwrite ($ fp , $ this ->message );
27- fflush ($ fp );
28- fclose ($ fp );
25+ file_put_contents ($ this ->targetFilePath , $ this ->message );
2926 }
3027}
Original file line number Diff line number Diff line change @@ -24,9 +24,6 @@ public function execute(): void
2424
2525 public function handleTimeout (): void
2626 {
27- $ fp = fopen ($ this ->targetFilePath , "w " );
28- fwrite ($ fp , $ this ->message );
29- fflush ($ fp );
30- fclose ($ fp );
27+ file_put_contents ($ this ->targetFilePath , $ this ->message );
3128 }
3229}
You can’t perform that action at this time.
0 commit comments