Skip to content

Commit d3a64dd

Browse files
authored
Merge pull request #42 from bertvandepoel/doc_fix2
Documentation for mixing asynchronous and synchronous blocking PHP
2 parents 9c25631 + 5ef6b42 commit d3a64dd

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ $zen->promise()->then(function ($result) {
109109
});
110110
```
111111

112+
#### Mixing synchronous and asynchronous PHP ####
113+
ReactPHP expects all PHP to be non-blocking. Therefore it's not easily possible to use launch or launchZen followed by regular blocking events in PHP. Currently there is a simple but dirty workaround. It's possible to manually tick the loop to have changes on zen-objects take effect.
114+
115+
```php
116+
$progress = new ProgressDialog('Step 1');
117+
$progress->setPulsate(TRUE);
118+
$progress->setAutoClose(TRUE);
119+
$progress_zen = $launcher->launchZen($progress);
120+
121+
// This regular command is blocking and breaks the asynchronous workflow
122+
$hostname = gethostname();
123+
124+
$progress_zen->setText('Step 2');
125+
$loop->tick();
126+
127+
// SQL is also regular blocking PHP
128+
$get_sync = $db_serv->prepare('SELECT last_sync FROM tbl_sync WHERE hostname=?');
129+
$get_sync->execute(array($hostname));
130+
$result_sync = $get_sync->fetch();
131+
```
132+
112133
### Builder
113134

114135
Additionally, the `Builder` implements an even simpler interface for commonly

0 commit comments

Comments
 (0)