php - send json response back to webhook caller

one text

I am creating a chatbot using Dialogflow. I need to use the webhook service. I have been able to successfully read the webhook request generated at my server using PHP. I am able to do use the data from webhook to do necessary stuff. But, I am not able to figure out the way to send JSON respone back to Dialogflow from PHP.

Code that I have tried:

<?php
    $webhookContent = "";
    $webhook = fopen('php://input' , 'rb');
    while (!feof($webhook)) {
        $webhookContent .= fread($webhook, 4096);
    }
    $data = json_decode($webhookContent);
    $json = '{"fulfillmentMessages": [{"text": {"text": ["Text response from webhook"]}}]}';
    $myfile = fopen("chatbot.txt", "a") or die("Unable to open file!");
    fwrite($myfile, $webhookContent."\r\n");
    fclose($myfile);
    echo json_encode($json);
    http_response_code(200);
?>

Above is a dummy of code that I am using. To send response I have tried the following options but nothing is working.

echo json_encode($json);
return json_encode($json);
return $json;

On Dialogflow it shows [empty response]

Source