Skip to content

Commit

Permalink
add new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Raeen committed Jan 23, 2021
1 parent 4e55704 commit 9634040
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Python/test6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import subprocess
import include.library.phpy as phpy
subprocess.call('ping '+phpy.get_data(1))
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,25 @@ $output = $python->gen("../Python/test2.py", $data1, $data2);
$output = $python->gen(path,datas...)
```

In $output you have python result also you can gen_line() function for return last line of result
In $output you have python result also you can ```gen_line()``` function for return last line of result

Also you can use ```gen_live_show()``` for print live output

Example:

```php
$site = "google.com";
$python->gen_live_show(
"../Python/test6.py", //file path
1, // time sleep between each output
1024, // bytes from the file pointer referenced by stream
[$site], // your data
function ($res) { //controller
return "<pre>$res</pre>";
}
);

```
If result is json , you should use this

```php
Expand Down
18 changes: 18 additions & 0 deletions core/Python.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ public function gen()
$cmd_result = shell_exec($command);
return $cmd_result;
}
public function gen_live_show($path, $time, $read, array $args, object $fun)
{
$resultargs = null;
foreach ($args as $send) {
$resultargs .= escapeshellarg(json_encode($send)) . " ";
}
$command = self::python_path . " " . $path . " " . $resultargs . " 2>&1";
$pid = popen($command, "r");
while (!feof($pid)) {
$res = fread($pid, $read);
$return = call_user_func($fun, $res);
echo $return;
flush();
ob_flush();
sleep($time);
}
pclose($pid);
}
public function gen_line()
{
$whattogen = func_get_args();
Expand Down
18 changes: 18 additions & 0 deletions php/test6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require_once "../vendor/autoload.php";

use app\core\App;

$app = new App();
$python = $app->python;

$site = "google.com";
$python->gen_live_show(
"../Python/test6.py",
1,
1024,
[$site],
function ($res) {
return "<pre>$res</pre>";
}
);

0 comments on commit 9634040

Please sign in to comment.