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

add 1ms delay after write to pipe #5

Merged
merged 1 commit into from
Jan 13, 2019
Merged

add 1ms delay after write to pipe #5

merged 1 commit into from
Jan 13, 2019

Conversation

anktx
Copy link
Contributor

@anktx anktx commented Jan 12, 2019

A small delay, needed on fast configurations, allow R-command to be executed.

Just a small test:

<?php

use Okvpn\R\Process\RProcess;
use Okvpn\R\UnixPipes;

require DIR . '/vendor/autoload.php';

$process = new RProcess(new UnixPipes(), '/usr/bin/R');
$process->start();

print_r($process->write('head(cars)')->getAllOutput());

Without delay we have:

Array
(
[0] => options(error=expression(NULL))
)

With this delay we have expected result:

Array
(
[0] => options(error=expression(NULL))
head(cars)
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
)

@anktx
Copy link
Contributor Author

anktx commented Jan 12, 2019

Also, a delay can be in pipe read cycle (/src/UnixPipes.php):

$data = fread($pipe, self::CHUNK_SIZE);
usleep(1000);
$read[$type] .= $data;

kachkaev/php-r have such delay: link.

@vtsykun vtsykun merged commit f241fca into okvpn:master Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants