Execute php code after giving the user 200 responsephp execute a background processHow can I sanitize user input with PHP?How to perform static code analysis in php?How do I expire a PHP session after 30 minutes?PHP: How to send HTTP response code?PHP code is not being executed, instead code shows on the pagePHP file_get_contents() follow Content-length headerHow can I proxy a request using PHP/cURL and proxy the response headers too?PHPs exec(..) prevents AJAX-responseGuzzle response with content-encoding: gzip comes back with incorrect content-length header

Integer Decision Variables Always Forced to Zero in Minimization Problem (MINLP)

When was the earliest opportunity the Voyager crew had to return to the Alpha quadrant?

A medieval fantasy adventurer lights a torch in a 100% pure oxygen room. What happens?

How is Team Scooby Doo (Mystery Inc.) funded?

Can I disable a battery powered device by reversing half of its batteries?

Understanding Cursive /Joined Writing in Irish Register Death

How to help my 2.5-year-old daughter take her medicine when she refuses to?

What was the relationship between Einstein and Minkowski?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

How can I discourage sharing internal API keys within a company?

Should I leave the first authorship of our paper to the student who did the project whereas I solved it?

Writing a love interest for my hero

Is it appropriate for a professor to require students to sign a non-disclosure agreement before being taught?

Parallel resistance in electric circuits

Glue or not to glue boots

Do all humans have an identical nucleotide sequence for certain proteins, e.g haemoglobin?

Double it your way

Is there an inconsistency about Natasha Romanoff's middle name in the MCU?

Uncovering the Accelerated Dragon opening

Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time

A shy person in a queue

What officially disallows US presidents from driving?

Do they still use tiger roars in the 2019 "Lion King" movie?

How do email clients "send later" without storing a password?



Execute php code after giving the user 200 response


php execute a background processHow can I sanitize user input with PHP?How to perform static code analysis in php?How do I expire a PHP session after 30 minutes?PHP: How to send HTTP response code?PHP code is not being executed, instead code shows on the pagePHP file_get_contents() follow Content-length headerHow can I proxy a request using PHP/cURL and proxy the response headers too?PHPs exec(..) prevents AJAX-responseGuzzle response with content-encoding: gzip comes back with incorrect content-length header






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am building an API. In it, there is some code that does not need to be executed for giving a response to the user. So I would like to give the response after the mandatory code is executed and also run the remaining code in the background.



This is a Linux server running apache and PHP7.2



 ignore_user_abort(true);
set_time_limit(0);

ob_start();

$api_key = $request->get('api_key');
$clientToken = ClientToken::where('token', $api_key)->where('is_blocked', 0)->get();
if (count($clientToken) > 0)
$dateTime = date_create_from_format('d-m-Y H:i:s a', $request->get('date_time'));
$missCallRequest = new MissCallRequest();
$missCallRequest->client_token_id = $clientToken[0]->id;
$missCallRequest->called_number = "+" . $request->get('called_number');
$missCallRequest->caller_number = $request->get('caller_number');
$missCallRequest->datetime = date_format($dateTime, 'Y-m-d H:i:s');
$missCallRequest->operator = $request->get('operator');
$missCallRequest->circle = $request->get('circle');
$missCallRequest->request_url = urldecode($request->fullUrl());
$missCallRequest->save();



$response = [
"status" => 200,
"message" => "Request Received",
];

echo json_encode($response); // send the response

// Get the size of the output.
$size = ob_get_length();

// Disable compression (in case content length is compressed).
header("Content-Encoding: none");

// Set the content length of the response.
header("Content-Length: $size");

// Close the connection.
header("Connection: close");

// Flush all output.
ob_end_flush();
ob_flush();
flush();

echo "hello";


This is responding after the mandatory code but it's not executing the rest of the code after responding.










share|improve this question
























  • You can't send header after output of json_encode

    – ivion
    Mar 28 at 10:02

















0















I am building an API. In it, there is some code that does not need to be executed for giving a response to the user. So I would like to give the response after the mandatory code is executed and also run the remaining code in the background.



This is a Linux server running apache and PHP7.2



 ignore_user_abort(true);
set_time_limit(0);

ob_start();

$api_key = $request->get('api_key');
$clientToken = ClientToken::where('token', $api_key)->where('is_blocked', 0)->get();
if (count($clientToken) > 0)
$dateTime = date_create_from_format('d-m-Y H:i:s a', $request->get('date_time'));
$missCallRequest = new MissCallRequest();
$missCallRequest->client_token_id = $clientToken[0]->id;
$missCallRequest->called_number = "+" . $request->get('called_number');
$missCallRequest->caller_number = $request->get('caller_number');
$missCallRequest->datetime = date_format($dateTime, 'Y-m-d H:i:s');
$missCallRequest->operator = $request->get('operator');
$missCallRequest->circle = $request->get('circle');
$missCallRequest->request_url = urldecode($request->fullUrl());
$missCallRequest->save();



$response = [
"status" => 200,
"message" => "Request Received",
];

echo json_encode($response); // send the response

// Get the size of the output.
$size = ob_get_length();

// Disable compression (in case content length is compressed).
header("Content-Encoding: none");

// Set the content length of the response.
header("Content-Length: $size");

// Close the connection.
header("Connection: close");

// Flush all output.
ob_end_flush();
ob_flush();
flush();

echo "hello";


This is responding after the mandatory code but it's not executing the rest of the code after responding.










share|improve this question
























  • You can't send header after output of json_encode

    – ivion
    Mar 28 at 10:02













0












0








0








I am building an API. In it, there is some code that does not need to be executed for giving a response to the user. So I would like to give the response after the mandatory code is executed and also run the remaining code in the background.



This is a Linux server running apache and PHP7.2



 ignore_user_abort(true);
set_time_limit(0);

ob_start();

$api_key = $request->get('api_key');
$clientToken = ClientToken::where('token', $api_key)->where('is_blocked', 0)->get();
if (count($clientToken) > 0)
$dateTime = date_create_from_format('d-m-Y H:i:s a', $request->get('date_time'));
$missCallRequest = new MissCallRequest();
$missCallRequest->client_token_id = $clientToken[0]->id;
$missCallRequest->called_number = "+" . $request->get('called_number');
$missCallRequest->caller_number = $request->get('caller_number');
$missCallRequest->datetime = date_format($dateTime, 'Y-m-d H:i:s');
$missCallRequest->operator = $request->get('operator');
$missCallRequest->circle = $request->get('circle');
$missCallRequest->request_url = urldecode($request->fullUrl());
$missCallRequest->save();



$response = [
"status" => 200,
"message" => "Request Received",
];

echo json_encode($response); // send the response

// Get the size of the output.
$size = ob_get_length();

// Disable compression (in case content length is compressed).
header("Content-Encoding: none");

// Set the content length of the response.
header("Content-Length: $size");

// Close the connection.
header("Connection: close");

// Flush all output.
ob_end_flush();
ob_flush();
flush();

echo "hello";


This is responding after the mandatory code but it's not executing the rest of the code after responding.










share|improve this question














I am building an API. In it, there is some code that does not need to be executed for giving a response to the user. So I would like to give the response after the mandatory code is executed and also run the remaining code in the background.



This is a Linux server running apache and PHP7.2



 ignore_user_abort(true);
set_time_limit(0);

ob_start();

$api_key = $request->get('api_key');
$clientToken = ClientToken::where('token', $api_key)->where('is_blocked', 0)->get();
if (count($clientToken) > 0)
$dateTime = date_create_from_format('d-m-Y H:i:s a', $request->get('date_time'));
$missCallRequest = new MissCallRequest();
$missCallRequest->client_token_id = $clientToken[0]->id;
$missCallRequest->called_number = "+" . $request->get('called_number');
$missCallRequest->caller_number = $request->get('caller_number');
$missCallRequest->datetime = date_format($dateTime, 'Y-m-d H:i:s');
$missCallRequest->operator = $request->get('operator');
$missCallRequest->circle = $request->get('circle');
$missCallRequest->request_url = urldecode($request->fullUrl());
$missCallRequest->save();



$response = [
"status" => 200,
"message" => "Request Received",
];

echo json_encode($response); // send the response

// Get the size of the output.
$size = ob_get_length();

// Disable compression (in case content length is compressed).
header("Content-Encoding: none");

// Set the content length of the response.
header("Content-Length: $size");

// Close the connection.
header("Connection: close");

// Flush all output.
ob_end_flush();
ob_flush();
flush();

echo "hello";


This is responding after the mandatory code but it's not executing the rest of the code after responding.







php laravel-5






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 9:46









Bimalmithran P.BBimalmithran P.B

3110 bronze badges




3110 bronze badges















  • You can't send header after output of json_encode

    – ivion
    Mar 28 at 10:02

















  • You can't send header after output of json_encode

    – ivion
    Mar 28 at 10:02
















You can't send header after output of json_encode

– ivion
Mar 28 at 10:02





You can't send header after output of json_encode

– ivion
Mar 28 at 10:02












1 Answer
1






active

oldest

votes


















0
















Use this to make sure the 200 is sent immediately



ignore_user_abort(true);
ob_start();
header("HTTP/1.1 200 OK");
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394487%2fexecute-php-code-after-giving-the-user-200-response%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    Use this to make sure the 200 is sent immediately



    ignore_user_abort(true);
    ob_start();
    header("HTTP/1.1 200 OK");
    header('Connection: close');
    header('Content-Length: '.ob_get_length());
    ob_end_flush();
    ob_flush();
    flush();





    share|improve this answer





























      0
















      Use this to make sure the 200 is sent immediately



      ignore_user_abort(true);
      ob_start();
      header("HTTP/1.1 200 OK");
      header('Connection: close');
      header('Content-Length: '.ob_get_length());
      ob_end_flush();
      ob_flush();
      flush();





      share|improve this answer



























        0














        0










        0









        Use this to make sure the 200 is sent immediately



        ignore_user_abort(true);
        ob_start();
        header("HTTP/1.1 200 OK");
        header('Connection: close');
        header('Content-Length: '.ob_get_length());
        ob_end_flush();
        ob_flush();
        flush();





        share|improve this answer













        Use this to make sure the 200 is sent immediately



        ignore_user_abort(true);
        ob_start();
        header("HTTP/1.1 200 OK");
        header('Connection: close');
        header('Content-Length: '.ob_get_length());
        ob_end_flush();
        ob_flush();
        flush();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 10:21









        justadevjustadev

        1702 silver badges14 bronze badges




        1702 silver badges14 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394487%2fexecute-php-code-after-giving-the-user-200-response%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현