"Swoole" when Swoole met php____php

Source: Internet
Author: User
Tags epoll install php php cli php script zend

Always want to write something swoole, after all, it redefined PHP, but never know how to hand handwriting.

Swoole involved in a lot of knowledge, each of the table, every time to write to find that there is no clue.

Swoole is an extension of PHP, the core purpose of which is to solve PHP in the implementation of server services may encounter a series of problems, these problems with the source of PHP is often not very efficient (execution efficiency) of the solution, generally will not use PHP to solve, So there will be a saying that says Swolle to redefine PHP.

In fact, Swoole also provides a framework, Swoole framework is based on the swoole extension design of a framework, to use this framework, or to first understand swoole extension.

The extended English name is the extension,php extension is a dynamic library compiled using the C language as the development language, based on the API provided by the Zend engine.

Children's shoes that have been developed like Dynamic library calls may be better understood, such as NDK development in Android

After configuring the extension properties in the PHP configuration file, you can refer to the dynamic library.

In other words, Swoole itself is written in C, which allows PHP to get some extra function.

Then it runs, and many of the features of Swoole can only run in CLI mode, and CLI mode is often the first problem encountered by many of the phper that have just contacted Swoole.

Sometimes it just needs a little change of mindset.

Let's now sort out the most common way to execute PHP code: Install Apache, PHP configure Apache to PHP for that directory and access that directory PHP file in the browser

More details are not mentioned here, after all, I believe that each phper is very familiar with this.

But here comes the first question, we know, PHP is a scripting language, the core feature of scripting language is not to compile, at any time to execute, and execute the script tool is the parser, and PHP parser is the Zend engine.

Strictly speaking, Zend is not the only option, but Zend is the most official. In addition, Zend Studio and Zend Engine are not the same thing, Zend in this article all refer to Zend Engine.

In other words, as long as there is a parser, write a good PHP script can be executed, and the Zend engine and Apache there is no absolute relationship between

In fact, Apahce called Zend to execute the PHP script and then output the execution results to the browser

So the so-called CLI mode (CommandLine, command-line mode), in fact, is directly under the command line to invoke the Zend engine to parse and execute the PHP script, and get the program output results of the PHP script execution mode.

In fact, PHP can also be used as a shell script oh, just like bash shell

Since the question is clear, how to operate in a system.

This article takes CentOS 7.5 as the system environment, Swoole is developed for the Linux system, Windows does not apply. One of the first topics in learning Swoole is understanding basic Linux system usage.

When you install PHP, find the installation directory of PHP, if it is the default installation, you can try Whereis command

# Some kind of simple way
whereis php
>/usr/local/bin/php;

Locate Whereis find these commands can be tried, with the aim of finding PHP

And then we'll write one of the most classic PHP scripts:

<?php
    //vi hello_cli.php
    echo ' Hello php cli ';

PHP tags do not seal when writing a pure PHP script

And then we execute it in the shell:

/usr/local/bin/php hello_cli.php
> Hello php cli

The first PHP in this code is an executable file that accepts a PHP script file as an input parameter and resolves to execute this php script file (via Zend).

No, the first CLI mode PHP program was executed successfully by you.

By default, PHP is installed in the $path directory, so you can omit the path prefix directly, the following call to PHP, all omit the path prefix.

Because Swoole is a pecl project, using PECL installation is the easiest way to recommend that first-contact children's shoes first use the PECL installation, after familiar with the swoole, and then consider using the compiled installation method to obtain more advanced functionality.

Pecl This tool will basically be installed in the same directory as PHP (often the $path directory)

PECL Install Swoole

Perform the following command to see if the installation was successful:

php-m | grep swoole
> Swoole

If the correct output of the swoole, then congratulations to you, this installation is very successful

Another common, more troublesome problem is that some children's shoes in the computer installed multiple PHP, and installed when not properly installed in the expected PHP extension directory, it will not work, the solution is to find out the various PHP installation directory and configuration relationships, select the correct directory to install.

In fact, this article has not officially started to introduce Swoole, are in the study before the preparation of swoole, Swoole threshold than the general application of PHP is much higher, if there is no network development and operating system of some knowledge, learning it is not an easy thing, learning curve is very steep.

I've been talking about it countless times in the group.

Many beginners will be criticized Swoole's manual is too vague, in fact, the knowledge is not enough, and the manual also gives the need for a list of prior knowledge, the following reference to the official website of the manual-learn swoole need what knowledge. multi-process/multithreading Understanding Linux Operating system processes and threads basic knowledge of Linux process/thread switching scheduling Understanding the basics of interprocess communication, such as pipelines, unixsocket, Message Queuing, shared memory sockets Understanding socket basic operations such as Accept/connect, SEND/RECV, close, listen, bind understanding socket sink buffer, send buffer, blocking/non-blocking, timeout concept io multiplexing Understanding Select /poll/epoll understand event loops based on Select/epoll implementations, reactor models understand readable events, writable events

TCP/IP network protocol Understanding TCP/IP Protocol Understanding TCP, UDP transport protocol debugging Tools using GDB to debug Linux programs using the Strace tracking process system calls use Tcpdump to track network communication processes other Linux system tools, such as PS, Lsof, top, Vmstat, Netstat, SAR, SS, etc.

Learning and understanding a new business is not an easy task, especially for the swoole of a certain subversive tool, patience and practice.

Calm to read the handbook, encountered not understand the noun learned to use search engine learning, Swoole manual is actually a big treasure house, the network development common problems in fact inside all involved.

From: Original link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.