PHPDaemon\SockJS\Methods\Generic::init PHP Method

init() public method

Constructor
public init ( ) : void
return void
    public function init()
    {
        $this->sessId = $this->attrs->sessId;
        $this->serverId = $this->attrs->serverId;
        $this->path = $this->attrs->path;
        // @TODO: revert timeout after request
        $this->upstream->setTimeouts($this->appInstance->config->networktimeoutread->value, $this->appInstance->config->networktimeoutwrite->value);
        $this->opts = $this->appInstance->getRouteOptions($this->attrs->path);
        $this->CORS();
        if ($this->isFinished()) {
            return;
        }
        if ($this->opts['cookie_needed'] && !$this instanceof Info) {
            if (isset($_COOKIE['JSESSIONID'])) {
                $val = $_COOKIE['JSESSIONID'];
                if (!is_string($val) || $val === '') {
                    $val = 'dummy';
                }
            } else {
                $val = 'dummy';
            }
            $this->setcookie('JSESSIONID', $val, 0, '/');
        }
        $this->contentType($this->contentType);
        if (!$this->cacheable) {
            $this->noncache();
            $this->header('X-Accel-Buffering: no');
        }
        if ($this->callbackParamEnabled) {
            if (!isset($_GET['c']) || !is_string($_GET['c']) || preg_match('~[^_\\.a-zA-Z0-9]~', $_GET['c'])) {
                $this->header('500 Internal Server Error');
                $this->out('"callback" parameter required');
                $this->finish();
                return;
            }
        }
        if (($f = $this->appInstance->config->heartbeatinterval->value) > 0) {
            $this->heartbeatTimer = setTimeout(function ($timer) {
                if (in_array('one-by-one', $this->pollMode)) {
                    $this->heartbeatOnFinish = true;
                    $this->stop();
                    return;
                }
                $this->sendFrame('h');
                if ($this->gcEnabled) {
                    $this->gcCheck();
                }
            }, $f * 1000000.0);
        }
        $this->afterHeaders();
        if ($this->poll) {
            $this->acquire(function () {
                $this->poll();
            });
        }
    }

Usage Example

Beispiel #1
0
    /**
     * Constructor
     * @return void
     */
    public function init()
    {
        parent::init();
        if ($this->isFinished()) {
            return;
        }
        echo str_repeat(' ', 1024);
        echo "\n\n";
        ?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2>Don't panic!</h2>
<script>
	document.domain = document.domain;
	var c = parent.<?php 
        echo $_GET['c'];
        ?>
;
	c.start();
	function p(d) {c.message(d);};
	window.onload = function() {c.stop();};
</script>
</body>
</html>
<?php 
    }
All Usage Examples Of PHPDaemon\SockJS\Methods\Generic::init