Start piping data

@return null
544127
public function start()
    {
        $metaData = array("columns"=>array());

        if ($this->countTotal) {
            $totalQuery = $this->prepareParams($this->totalQuery, $this->sqlParams);
            $stm = $this->connection->prepare($totalQuery);
            $this->bindParams($stm, $this->sqlParams);
            $stm->execute();
            $error = $stm->errorInfo();
            if ($error[2]!=null) {
                throw new \Exception("Query Error >> [".$error[2]."] >> $totalQuery");
                return;
            }
            $row = $stm->fetch();
            $result = $row[0];
            $metaData['totalRecords'] = $result;
        }

        if ($this->countFilter) {
            $filterQuery = $this->prepareParams($this->filterQuery, $this->sqlParams);
            $stm = $this->connection->prepare($filterQuery);
            $this->bindParams($stm, $this->sqlParams);
            $stm->execute();
            $error = $stm->errorInfo();
            if ($error[2]!=null) {
                throw new \Exception("Query Error >> [".$error[2]."] >> $filterQuery");
                return;
            }
            $row = $stm->fetch();
            $result = $row[0];
            $metaData['filterRecords'] = $result;
        }
        $row = null;

        $query = $this->prepareParams($this->query, $this->sqlParams);
        // echo "pdodatasource start query=$query <br>";
        $stm = $this->connection->prepare($query);
        $this->bindParams($stm, $this->sqlParams);
        $stm->execute();

        $error = $stm->errorInfo();
        // if($error[2]!=null)
        if ($error[0]!='00000') {
            throw new \Exception("Query Error >> [".$error[2]."] >> $query");
            return;
        }

        $driver = strtolower($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME));
        $metaSupportDrivers = array('dblib', 'mysql', 'pgsql', 'sqlite');
        $metaSupport = false;
        foreach ($metaSupportDrivers as $supportDriver) {
            if (strpos($driver, $supportDriver) !== false) {
                $metaSupport = true;
            }
        }
            
        if (!$metaSupport) {
            $row = $stm->fetch(PDO::FETCH_ASSOC);
            $cNames = empty($row) ? array() : array_keys($row);
            $numcols = count($cNames);
        } else {
            $numcols = $stm->columnCount();
        }

        // $metaData = array("columns"=>array());
        for ($i=0;$i<$numcols;$i++) {
            if (! $metaSupport) {
                $cName = $cNames[$i];
                $cType = $this->guessTypeFromValue($row[$cName]);
            } else {
                $info = $stm->getColumnMeta($i);
                $cName = $info["name"];
                $cType = $this->guessType($info["native_type"]);

            }
            $metaData["columns"][$cName] = array(
                "type"=>$cType,
            );
            switch($cType)
            {
            case "datetime":
                $metaData["columns"][$cName]["format"] = "Y-m-d H:i:s";
                break;
            case "date":
                $metaData["columns"][$cName]["format"] = "Y-m-d";
                break;
            case "time":
                $metaData["columns"][$cName]["format"] = "H:i:s";
                break;
            }
        }
                
        $this->sendMeta($metaData, $this);
        $this->startInput(null);
        
        $numberColumnList = array();
        foreach ($metaData["columns"] as $cName=>$cMeta) {
            if ($cMeta["type"]=="number") {
                array_push($numberColumnList, $cName);
            }
        }
                        
        if (! isset($row)) {
            $row=$stm->fetch(PDO::FETCH_ASSOC);
        }
            
        while ($row) {
            // print_r($row); echo '<br>';
            foreach ($numberColumnList as $cName) {
                    $row[$cName]+=0;
            }
            $this->next($row, $this);
            $row=$stm->fetch(PDO::FETCH_ASSOC);
        }
        $this->endInput(null);
    }
268590
public function Start(){
            if(file_exists($this->sModuleDiretory . SP . "status.txt")){
                $iStatus = intval(file_get_contents($this->sModuleDiretory . SP . "status.txt"));
                $bStatus = ($iStatus == 1);
                Storage::Set("app.".$this->sModuleName.".enabled", $bStatus);
            }
            else{
                $bStatus = true;
                file_put_contents($this->sModuleDiretory . SP . "status.txt", "1");
                Storage::Set("app.".$this->sModuleName.".enabled", true);
            }
            
            if($bStatus){
                Storage::SetArray("class.list", "module.".$this->sModuleName, $this->sModuleDiretory . "core" . SP);
                
                //Diretory Paths
                Storage::Set("app.".$this->sModuleName, $this->sModuleDiretory);
                Storage::Set("app.".$this->sModuleName.".shell.css", $this->sModuleDiretory . "shell" . SP . "css" . SP);
                Storage::Set("app.".$this->sModuleName.".shell.tpl", $this->sModuleDiretory . "shell" . SP . "tpl" . SP);
                Storage::Set("app.".$this->sModuleName.".shell.js", $this->sModuleDiretory . "shell" . SP . "js" . SP);
                Storage::Set("app.".$this->sModuleName.".shell.img", $this->sModuleDiretory . "shell" . SP . "img" . SP);
                
                //Web Paths
                Storage::Set("virtual.".$this->sModuleName.".shell.img", Storage::Join("route.root", "app/" . $this->sModuleName . "/shell/img/"));
                Storage::Set("virtual.".$this->sModuleName.".shell.tpl", Storage::Join("route.root", "app/" . $this->sModuleName . "/shell/tpl/"));
                Storage::Set("virtual.".$this->sModuleName.".shell.js", Storage::Join("route.root", "app/" . $this->sModuleName . "/shell/js/"));
                Storage::Set("virtual.".$this->sModuleName.".shell.css", Storage::Join("route.root", "app/" . $this->sModuleName . "/shell/css/"));
                        
                //Loading submodules
                if(is_dir($this->sModuleDiretory  . "modules")){
                    $aModulesDirectories = glob(($this->sModuleDiretory . "modules" . SP . "*"), GLOB_ONLYDIR);

                    foreach($aModulesDirectories as $sModuleDiretory){
                        if(file_exists($sModuleDiretory . SP . "status.txt"))
                            $bStatus = (intval(file_get_contents($sModuleDiretory . SP . "status.txt")) == 1);
                        else
                            $bStatus = false;

                        if($bStatus){
                            if(file_exists($sModuleDiretory . SP . "settings.php") && $bStatus)
                                require_once($sModuleDiretory . SP . "settings.php");       

                            if(file_exists($sModuleDiretory . SP . "include.php") && $bStatus)
                                require_once($sModuleDiretory . SP . "include.php");  

                            if(file_exists($sModuleDiretory . SP . "routes.php") && $bStatus)
                                require_once($sModuleDiretory . SP . "routes.php");

                            if(file_exists($sModuleDiretory . SP . "events.php") && $bStatus)
                                require_once($sModuleDiretory . SP . "events.php");
                        }
                    }
                }
            }            
        }
1146416
public static function start()
    {
        if (Bootstrap::$pid && Thread\Generic::ifExistsByPid(Bootstrap::$pid)) {
            Daemon::log('[START] phpDaemon with pid-file \'' . Daemon::$config->pidfile->value . '\' is running already (PID ' . Bootstrap::$pid . ')');
            exit(6);
        }

        Daemon::init();
        $pid = Daemon::spawnMaster();
        file_put_contents(Daemon::$config->pidfile->value, $pid);
    }
702488
public function start()
	{
		for ($i = 0; $i < $this->_nProcesses; $i++) {
			$this->_nCurrentProcess = $i;
			$this->_aPids[$i] = $nPid = pcntl_fork();
			if ($nPid == -1) {
				$this->_log('WARNING: Could not fork');
			} else if ($nPid > 0) {
				// Parent process
				$this->_log("INFO: Forked process PID {$nPid}");
				$this->_nRunningProcesses++;
			} else {
				// Child process
				try {
					parent::connect();
				} catch (ApnsPHP_Exception $e) {
					$this->_log('ERROR: ' . $e->getMessage() . ', exiting...');
					exit(1);
				}
				$this->_mainLoop();
				parent::disconnect();
				exit(0);
			}
		}
	}
666674
public function start()
    {
        $metaData = array("columns"=>array());

        if ($this->countTotal) {
            $totalQuery = $this->bindParams($this->totalQuery, $this->sqlParams);
            $totalResult = $this->connection->query($totalQuery);
            if ($totalResult===false) {
                throw new \Exception("Error on query >>> ".$this->connection->error);
            }
            $row = $totalResult->fetch_array();
            $result = $row[0];
            $metaData['totalRecords'] = $result;
        }

        if ($this->countFilter) {
            $filterQuery = $this->bindParams($this->filterQuery, $this->sqlParams);
            $filterResult = $this->connection->query($filterQuery);
            if ($filterResult===false) {
                throw new \Exception("Error on query >>> ".$this->connection->error);
            }
            $row = $filterResult->fetch_array();
            $result = $row[0];
            $metaData['filterRecords'] = $result;
        }

        $query = $this->bindParams($this->query, $this->sqlParams);
        $result = $this->connection->query($query);
        
        if ($result===false) {
            throw new \Exception("Error on query >>> ".$this->connection->error);
        }

        $finfo = $result->fetch_fields();

        
        $numcols = count($finfo);
        for ($i=0; $i<$numcols; $i++) {
            $type = $this->mapFieldTypeToBindType($finfo[$i]->type);
                $metaData["columns"][$finfo[$i]->name] = array(
                        "type"=>$type,
                    );
            switch($type)
            {
            case "datetime":
                $metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d H:i:s";
                break;
            case "date":
                $metaData["columns"][$finfo[$i]->name]["format"] = "Y-m-d";
                break;
            case "time":
                $metaData["columns"][$finfo[$i]->name]["format"] = "H:i:s";
                break;          
            }
        }

        $this->sendMeta($metaData, $this);
    
        $this->startInput(null);
        
        while ($row = $result->fetch_assoc()) {
            $this->next($row, $this);
        }

        $this->endInput(null);
    }
876548
public function start() {
		if($this->isStarted) {
			throw new \Exception(get_called_class() . ' is already started, use ' . get_called_class() . '::getInstance()->isStarted() to check it.');
		}
		$this->isStarted = true;

		if($this->handleErrors) {
			$this->initErrorsHandler();
		}
		if($this->handleExceptions) {
			$this->initExceptionsHandler();
		}
	}
24431
public function startTrans()
    {
        $this->initConnect(true);
        if (!$this->linkID) {
            return false;
        }

        ++$this->transTimes;
        try {
            if (1 == $this->transTimes) {
                $this->linkID->beginTransaction();
            } elseif ($this->transTimes > 1 && $this->supportSavepoint()) {
                $this->linkID->exec(
                    $this->parseSavepoint('trans' . $this->transTimes)
                );
            }

        } catch (\PDOException $e) {
            if ($this->isBreak($e)) {
                return $this->close()->startTrans();
            }
            throw $e;
        } catch (\Exception $e) {
            if ($this->isBreak($e)) {
                return $this->close()->startTrans();
            }
            throw $e;
        }
        return null;
    }
89063
protected function startQuery()
    {
        $sessionOK = $this->initialiseSession();
        if ($sessionOK) {
            $searchReplyString = $this->fetchURL($this->pazpar2SearchURL());
            $searchReply = GeneralUtility::xml2array($searchReplyString);

            if ($searchReply) {
                $status = $searchReply['status'];
                if ($status === 'OK') {
                    $this->queryIsRunning = true;
                } else {
                    GeneralUtility::devLog('pazpar2 search command status is not "OK" but "' . $status . '"', 'pazpar2', 3);
                }
            } else {
                GeneralUtility::devLog('could not parse pazpar2 search reply', 'pazpar2', 3);
            }
        }
    }
144392
protected function start() {
        $args = $this->getServerArguments();
        if ($args['command']) {
            $commandClass = $this->getCommandClassFromNameAndModule($args['command'], null);
        } else {
            $commandClass = $this->notFoundCommand;
        }
        if (!class_exists($commandClass)) {
            $this->alert('Command ' . $commandClass . ' not found!', array(
                'requestedCommand' => $args['command'],
                'requestedModule' => '-'
            ));
            $commandClass = $this->notFoundCommand;
        }

        $command = $this->loadCommand($commandClass);
        $command->setActiveAction($args['action']);
        $command->run($args['params']);
    }
1024785
public function start()
    {
        // echo "query=" . $this->query . '<br>';
        $metaData = array("columns"=>array());

        if ($this->countTotal) {
            $query = $this->bindParams($this->totalQuery, $this->sqlParams);
            $stmt = sqlsrv_query($this->connection, $query);
            if ($stmt === false) {
                die(print_r(sqlsrv_errors(), true));
            } 
            $row = sqlsrv_fetch_array($stmt);
            $total = $row[0];
            $metaData['totalRecords'] = $total;
        }

        if ($this->countFilter) {
            $query = $this->bindParams($this->filterQuery, $this->sqlParams);
            $stmt = sqlsrv_query($this->connection, $query);
            if ($stmt === false) {
                die(print_r(sqlsrv_errors(), true));
            } 
            $row = sqlsrv_fetch_array($stmt);
            $total = $row[0];
            $metaData['filterRecords'] = $total;
        }

        $query = $this->bindParams($this->query, $this->sqlParams);
        $stmt = sqlsrv_query($this->connection, $query);
        if ($stmt === false) {
            die(print_r(sqlsrv_errors(), true));
        } 

        $finfo = sqlsrv_field_metadata($stmt);
        
        $numcols = count($finfo);
        for ($i=0; $i<$numcols; $i++) {
            $type = $this->mapFieldTypeToBindType($finfo[$i]['Type']);
            $metaData["columns"][$finfo[$i]['Name']] = array(
                "type"=>$type,
            );
            switch($type)
            {
            case "datetime":
                $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d H:i:s";
                break;
            case "date":
                $metaData["columns"][$finfo[$i]['Name']]["format"] = "Y-m-d";
                break;
            }
        }
                
        $this->sendMeta($metaData, $this);
    
        $this->startInput(null);
        
        while ( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) {
            $this->next($row, $this);
        }
    
        $this->endInput(null);
    }
24398
public function start()
    {
        try {
            $this->createClientSocket();
            $this->createWorkerJobSocket();
            $this->createWorkerReplySocket();
            $this->startWorkerPools();
            $this->loop->addPeriodicTimer(5, [$this, 'monitorChildProcesses']);
            $this->loop->addPeriodicTimer(10, [$this, 'monitorQueue']);
            $this->loop->run();
        } catch (ServerException $e) {
            $errorMsgPattern = 'Server error: %s (%s:%d)';
            $this->logger->emergency(sprintf($errorMsgPattern, $e->getMessage(), $e->getFile(), $e->getLine()));
        }
    }
102034
public function main()
    {
        try {
            // Log
            $this->log('Started ', $this->loglevel);
            // Initialize //
            $this->prepare();
            $haveExecuted = false;
            // Validate O.S. applicability
            if ($this->isValidOs()) {
                // Build the command //
                $this->buildCommand();
                // Process //
                $totalFiles = 0;
                $totalDirs = 0;
                $fileNames = [];
                // - FileSets
                foreach ($this->filesets as $fs) {
                    $currentType = $this->type;
                    if ($fs instanceof DirSet) {
                        if ($this->type !== self::$types['DIR']) {
                            $this->log(
                                "Found a nested dirset but type is $this->type . "
                                . "Temporarily switching to type=\"dir\" on the"
                                . " assumption that you really did mean"
                                . " <dirset> not <fileset>.",
                                Project::MSG_DEBUG
                            );
                            $currentType = 'dir';
                        }
                    }
                    $base = $fs->getDir($this->project);
                    $ds = $fs->getDirectoryScanner($this->project);
                    if ($currentType !== self::$types['DIR']) {
                        $s = $this->getFiles($base, $ds);
                        foreach ($s as $fileName) {
                            $totalFiles++;
                            $fileNames[] = $fileName;
                            $baseDirs[] = $base;
                        }
                    }
                    if ($currentType !== self::$types['FILE']) {
                        $s = $this->getDirs($base, $ds);
                        foreach ($s as $fileName) {
                            $totalDirs++;
                            $fileNames[] = $fileName;
                            $baseDirs[] = $base;
                        }
                    }
                    if (count($fileNames) === 0 && $this->skipEmpty) {
                        $this->logSkippingFileset($currentType, $ds, $base);
                        continue;
                    }
                    $this->process(
                        $fs->getDirectoryScanner($this->project)->getIncludedFiles(),
                        $fs->getDir($this->project)
                    );
                    $haveExecuted = true;
                }
                unset($this->filesets);
                // - FileLists
                /**
                 * @var FileList $fl
                 */
                foreach ($this->filelists as $fl) {
                    $totalFiles++;
                    $this->process($fl->getFiles($this->project), $fl->getDir($this->project));
                    $haveExecuted = true;
                }
                unset($this->filelists);
            }
            if ($haveExecuted) {
                $this->log(
                    "Applied " . $this->commandline->getExecutable() . " to "
                    . $totalFiles . " file"
                    . ($totalFiles !== 1 ? "s" : "") . " and "
                    . $totalDirs . " director"
                    . ($totalDirs !== 1 ? "ies" : "y") . ".",
                    $this->loglevel
                );
            }
            /// Cleanup //
            $this->cleanup();
            // Log
            $this->log('End ', $this->loglevel);
        } catch (IOException | NullPointerException | UnexpectedValueException $e) {
            throw new BuildException('Execute failed: ' . $e, $e, $this->getLocation());
        }
    }
240465
protected function start()
    {
        $this->processes[] = $this->createProcess()->handleOutputUsing(function ($type, $line) {
            call_user_func($this->output, $type, $line);
        });

        return $this;
    }
1130279
public function start()
    {
        if (0 !== $this->oid) {
            throw new StatusError('The context has already been started.');
        }

        list($parent, $child) = Stream\pair();

        switch ($pid = pcntl_fork()) {
            case -1: // Failure
                throw new ForkException('Could not fork process!');

            case 0: // Child
                // @codeCoverageIgnoreStart

                // Create a new event loop in the fork.
                Loop\loop($loop = Loop\create(false));

                $channel = new ChannelledStream($pipe = new DuplexPipe($parent));
                fclose($child);

                $coroutine = new Coroutine($this->execute($channel));
                $coroutine->done();

                try {
                    $loop->run();
                    $code = 0;
                } catch (\Throwable $exception) {
                    $code = 1;
                }

                $pipe->close();

                exit($code);

                // @codeCoverageIgnoreEnd

            default: // Parent
                $this->pid = $pid;
                $this->oid = posix_getpid();
                $this->channel = new ChannelledStream($this->pipe = new DuplexPipe($child));
                fclose($parent);
        }
    }
1276897
public function start()
    {
        try {
            /* raw input handler */
            $raw = file_get_contents(php_sapi_name() === 'cli' ? 'php://stdin' : 'php://input');
            if ($this->rawInputHandler !== null) {
                call_user_func($this->rawInputHandler, $raw);
            }
            /* parse the incoming request */
            $request = new Request($raw);
            /* find the CallFlow */
            if (array_key_exists($request->app, $this->cf)) {
                $cf = $this->cf[$request->app];
            } elseif (array_key_exists('*', $this->cf)) {
                $cf = $this->cf['*'];
            } else {
                throw new \Exception("CallFlow for '{$request->app}' Not Found", 404);
            }
            /* call the previous callback. if response is null, we just received a HANGUP */
            if (($label = $cf->callback($request)) !== null) {
                /* call the next label */
                $response = $cf->execute($label);
                /* output response */
                echo $response->getJSON();
            }
        } catch (\Exception $e) {
            /* if an exception is thrown, we reply with an HTTP error */
            echo $this->httpError($e->getMessage(), $e->getCode());
        }
        $output = ob_get_contents();
        /* raw output handler */
        if ($this->rawOutputHandler !== null) {
            call_user_func($this->rawOutputHandler, $output);
        }
        /* Content-Type */
        header('Content-Type: '.self::CONTENT_TYPE);
        /* flush output buffer */
        ob_end_flush();
    }
694645
protected function starting_output() {
        global $CFG;

        if (!during_initial_install()) {
            $this->blocks->load_blocks();
            if (empty($this->_block_actions_done)) {
                $this->_block_actions_done = true;
                if ($this->blocks->process_url_actions($this)) {
                    redirect($this->url->out(false));
                }
            }
            $this->blocks->create_all_block_instances();
        }

        // If maintenance mode is on, change the page header.
        if (!empty($CFG->maintenance_enabled)) {
            $this->set_button('<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
                    '/settings.php?section=maintenancemode">' . get_string('maintenancemode', 'admin') .
                    '</a> ' . $this->button);

            $title = $this->title;
            if ($title) {
                $title .= ' - ';
            }
            $this->set_title($title . get_string('maintenancemode', 'admin'));
        }

        $this->initialise_standard_body_classes();
    }
271756
public function start(): void
    {
        // In case Lambda stopped our process (e.g. because of a timeout) we need to make sure PHP-FPM has stopped
        // as well and restart it
        if ($this->isReady()) {
            $this->killExistingFpm();
        }

        if (! is_dir(dirname(self::SOCKET))) {
            mkdir(dirname(self::SOCKET));
        }

        /**
         * --nodaemonize: we want to keep control of the process
         * --force-stderr: force logs to be sent to stderr, which will allow us to send them to CloudWatch
         */
        $this->fpm = new Process(['php-fpm', '--nodaemonize', '--force-stderr', '--fpm-config', $this->configFile]);
        $this->fpm->setTimeout(null);
        $this->fpm->start(function ($type, $output): void {
            // Send any PHP-FPM log to CloudWatch
            echo $output;
        });

        $connection = new UnixDomainSocket(self::SOCKET, 1000, 30000);
        $this->client = new Client($connection);

        $this->waitUntilReady();
    }