MCPcopy Create free account
hub / github.com/buggregator/server / StartPHPProcess

Function StartPHPProcess

modules/vardumper/php_process.go:34–80  ·  view source on GitHub ↗

StartPHPProcess extracts the embedded PHP binary and starts it.

()

Source from the content-addressed store, hash-verified

32
33// StartPHPProcess extracts the embedded PHP binary and starts it.
34func StartPHPProcess() (*PHPProcess, error) {
35 // Extract embedded binary to temp file.
36 tmpFile, err := os.CreateTemp("", "vardumper-parser-*")
37 if err != nil {
38 return nil, fmt.Errorf("create temp file: %w", err)
39 }
40
41 if _, err := tmpFile.Write(phpBinary); err != nil {
42 tmpFile.Close()
43 os.Remove(tmpFile.Name())
44 return nil, fmt.Errorf("write PHP binary: %w", err)
45 }
46 tmpFile.Close()
47
48 if err := os.Chmod(tmpFile.Name(), 0755); err != nil {
49 os.Remove(tmpFile.Name())
50 return nil, fmt.Errorf("chmod PHP binary: %w", err)
51 }
52
53 slog.Info("starting PHP VarDumper parser", "path", tmpFile.Name())
54
55 cmd := exec.Command(tmpFile.Name())
56 stdin, err := cmd.StdinPipe()
57 if err != nil {
58 os.Remove(tmpFile.Name())
59 return nil, fmt.Errorf("stdin pipe: %w", err)
60 }
61
62 stdout, err := cmd.StdoutPipe()
63 if err != nil {
64 os.Remove(tmpFile.Name())
65 return nil, fmt.Errorf("stdout pipe: %w", err)
66 }
67
68 cmd.Stderr = os.Stderr
69
70 if err := cmd.Start(); err != nil {
71 os.Remove(tmpFile.Name())
72 return nil, fmt.Errorf("start PHP process: %w", err)
73 }
74
75 return &PHPProcess{
76 cmd: cmd,
77 stdin: stdin,
78 stdout: bufio.NewReaderSize(stdout, 1024*1024), // 1MB buffer for large HTML dumps
79 }, nil
80}
81
82// Parse sends a base64 payload to the PHP process and reads the JSON result.
83func (p *PHPProcess) Parse(base64Payload string) (*ParseResult, error) {

Callers 1

StartPHPMethod · 0.85

Calls 2

NameMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected