Coder Social home page Coder Social logo

Comments (5)

laruence avatar laruence commented on June 10, 2024

这是说Header已经被发送过了,或者之前已经有输出了,不确定是否是Swoole会默认输出什么东西?

from yar.

laruence avatar laruence commented on June 10, 2024
PHP_METHOD(yar_server, handle)
{
    if (SG(headers_sent)) {
        php_error_docref(NULL, E_WARNING, "headers already has been sent");
        RETURN_FALSE;

@matyhtf 有没有可能swoole在一个请求结束后,没有重置这个SG(headers_sent)标志?

from yar.

matyhtf avatar matyhtf commented on June 10, 2024

@laruence 由于 swoole 是并发服务器,没有SG(headers_sent)全局变量的概念。状态是绑定在RequestResponse对象上的。请求响应的处理不会设置SG(headers_sent)全局变量状态。只有局部变量,没有任何全局变量。

在 swoole 中也无法使用 PHP 的header()setcookie() 等函数

想不到太好的解决办法,这里应该有好几个地方不兼容。

<?php
$http = new swoole_http_server("127.0.0.1", 9501);

$http->on("start", function ($server) {
    echo "Swoole http server is started at http://127.0.0.1:9501 \n";
});

$http->on("request", function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->cookie("test", "value", time() + 3600);
    var_dump($requset->get, $requset->post, $request->cookie);
    $response->end("Hello World\n");
});

$http->start();

from yar.

matyhtf avatar matyhtf commented on June 10, 2024

如果要兼容 swoole 或者 workerman 这样的服务器,yar 需要提供设置自定义 header、setcookie 的 API

from yar.

laruence avatar laruence commented on June 10, 2024

hmm, 看起来没那么简单,不过在swoole场景下,还要yar干嘛呢?或者就不http了?

from yar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.