написать ошибку EPIPE при выполнении php кода на node js дочернем процессе - PullRequest
0 голосов
/ 16 апреля 2020

Я пытаюсь запустить php код в одной из моих лямбда-функций, следуя указаниям, предоставленным https://github.com/awspilot/aws-lambda-php-template. Этот код был реализован несколько лет go, и он работал хорошо. Но вдруг я начал выдавать эту ошибку

    ERROR Uncaught Exception { "errorType": "Error", "errorMessage": "write EPIPE", "code": "EPIPE", "errno": "EPIPE", "syscall": "write", "stack": [ "Error: write EPIPE", " at WriteWrap.afterWrite [as oncomplete] (net.js:789:14)" ] }

code index. js

    var spawn = require('child_process').spawn
    var stream = require('stream')

    exports.handler = function( event, context ) {

        var php =spawn('./php', ['index.php'])
        php.stdin.setEncoding = 'utf-8';
        php.stdin.write(JSON.stringify(event) + "\n")
        php.stdin.end()

        //php.stdout.pipe(process.stdout);



        php.stdout.on('data', function (data) {
            console.log( data.toString() );
        });

        php.stderr.on('data', function (data) {
            console.log( data.toString() );
        });

    //var readable = new stream.Readable();
    //readable._read = function noop() {}; // See note below
    //readable.push('test me!');
    //readable.push(null);
    //readable.pipe(php.stdin)

        php.on('exit', function (code) {
            console.log('child process exited with code ' + code);
            context.done()
        });

    }

index. php

    <?php
        $body = '';
        while (FALSE !== ($line = fgets(STDIN))) {
        $body.= $line;
        }

        $event = json_decode($body,true);
        var_dump($event);

        print_r(get_loaded_extensions());

    ?>

Я также создал проблему в выпуске github Может кто-нибудь помочь мне решить эту проблему?

код тестирования точно такой же, как в библиотеке github. Спасибо

...