php -S 0.0.0.0:8001 ./Serve.phpsudo python ./client.py| #!/usr/bin/env python3 | |
| import pycurl | |
| import certifi | |
| import subprocess | |
| from io import BytesIO | |
| class ProcessReader: | |
| process: subprocess.Popen | |
| def __init__(self, process: subprocess.Popen): | |
| self.process = process | |
| def read_callback(self, size): | |
| try: | |
| self.process.wait(0) | |
| except subprocess.TimeoutExpired: | |
| pass | |
| print('DOING WRITE') | |
| if self.process.returncode is not None and self.process.returncode > 0: | |
| raise Exception('Interrupting! The process exited early') | |
| return self.process.stdout.read(size) | |
| process = subprocess.Popen('/bin/bash -c "echo hehe; dmesg; sleep 1; echo duuupa; dmesg; sleep 1; exit 1"', shell=True, stdout=subprocess.PIPE) | |
| body = BytesIO() | |
| curl = pycurl.Curl() | |
| curl.setopt(curl.URL, 'http://localhost:8001') | |
| curl.setopt(curl.CAINFO, certifi.where()) | |
| curl.setopt(curl.CUSTOMREQUEST, 'POST') | |
| curl.setopt(curl.UPLOAD, 1) | |
| curl.setopt(curl.READFUNCTION, ProcessReader(process).read_callback) | |
| curl.setopt(curl.WRITEFUNCTION, body.write) | |
| curl.setopt(curl.VERBOSE, True) | |
| curl.perform() | |
| curl.close() | |
| print(body.getvalue().decode('utf-8')) |
| <?php declare(strict_types=1); | |
| ignore_user_abort(true); | |
| var_dump(file_get_contents('php://input')); | |
| sleep(10); | |
| $f = fopen('test.log', 'wb'); | |
| fwrite($f, 'connection_aborted() = ' . var_export(connection_aborted(), true)); | |
| fclose($f); |