{"record":{"id":"a1490265351f1a36","repo":"phalcon/cphalcon","slug":"response-was-already-sent","errorCode":null,"errorMessage":"Response was already sent","messagePattern":"Response was already sent","errorType":"exception","errorClass":"Phalcon\\Http\\Response\\Exceptions\\ResponseAlreadySent","httpStatus":null,"severity":"error","filePath":"phalcon/Http/Response.zep","lineNumber":309,"sourceCode":"    /**\n     * Resets all the established headers\n     */\n    public function resetHeaders() -> <ResponseInterface>\n    {\n        this->headers->reset();\n\n        return this;\n    }\n\n    /**\n     * Prints out HTTP response to the client\n     */\n    public function send() -> <ResponseInterface>\n    {\n        var content, file;\n\n        if unlikely this->sent {\n            throw new ResponseAlreadySent();\n        }\n\n        this->sendHeaders();\n        this->sendCookies();\n\n        /**\n         * Output the response body\n         */\n        let content = this->content;\n\n        if content != null {\n            echo content;\n        } else {\n            let file = this->file;\n\n            if typeof file == \"string\" && strlen(file) {\n                readfile(file);\n            }","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Http/Response.zep#L291-L327","documentation":"Response::send() sets an internal sent flag once headers and body have been emitted; calling send() again on the same object throws ResponseAlreadySent to prevent duplicated headers and body output. The companion check is isSent().","triggerScenarios":"$response->send(); $response->send(); an exception handler that sends its own response and then the normal lifecycle sends again; middleware or event listeners calling send() on the shared response object.","commonSituations":"Error handlers that send and then let the main loop continue; 'after' middleware sending before the front controller does; code migrated from frameworks where double-send was ignored.","solutions":["Guard every send: if (!$response->isSent()) { $response->send(); }","Send from exactly one place (front controller) and return Response objects everywhere else","In exception handlers, send and then exit/return so the main loop does not resend"],"exampleFix":"// before\n$this->response->send();\n// ... later, framework front controller also runs:\n$this->response->send(); // ResponseAlreadySent\n\n// after\nif (!$this->response->isSent()) {\n    $this->response->send();\n}","handlingStrategy":"validation","validationCode":"if (!$response->isSent()) {\n    $response->send();\n}","typeGuard":null,"tryCatchPattern":"try { $response->send(); } catch (\\Phalcon\\Http\\Response\\Exceptions\\ResponseAlreadySent $e) { // body already delivered: log and continue idempotently\n    error_log('Response already sent; skipping duplicate send');\n}","preventionTips":["Centralize send() in one front-controller location","Guard every secondary send with isSent()","Make exception handlers exit or return after sending their response"],"tags":["php","phalcon","response","http","output"],"backgroundTag":"output-already-sent","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}