An explanation of the differences between include and require in PHP

Source: Internet
Author: User

Browser compatibility: Goeasy push supports websocket and polling two connections to support all versions of IE6 and above, while also supporting other browsers such as Firefox, Chrome, Safari, and more.

Support for different development languages: Goeasy Push provides a RESTful API interface that enables real-time push through the RESTful API, regardless of which language your daemon uses. such as: Java, PHP, C #, Ruby, Python, C, C + +, ASP. NET, node. js ...

Support backstage and front-end push: Backstage with restful API, front desk with goeasy.js; The use is very simple!

PHP Web Real-time messaging backend server push technology-goeasy

Let me introduce you to the steps of using Goeasy:

1. You need to register an account with the Goeasy website and create an app that will generate two key:publish keys and subscribe keys by default when the app is created.

2. Front-desk real-time subscription and reception

Simply introduce Goeasy.js and then call Goeasy's Subscribe method to subscribe to a channel, either with publish key or subscribe key at the time of subscription. The callback function of the subscribe parameter onmessage can receive the message in real time.

3. Front-desk real-time push

It is still necessary to introduce goeasy.js (if the page has already been introduced and not be introduced), and then call Goeasy's publish method to push the message to the subscribed channel, with only publish key being pushed.

4. Real-time push in the background

Call the Goeasy Restful API and post to the Http://goeasy.io/goeasy/publish, along with the three necessary parameters:

Appkey:publish Key

Channel: The channel you subscribed to

Content: Push Contents

It's that simple.

Below I have written a small instance of the post, the use of Java script in the Web page to subscribe, push, receive, and unsubscribe example, inside the Appkey with the Goeasy official demo Appkey.

=subsibe () "/> </body>

The performance of the Require () statement is similar to include (), which includes and runs the specified file. The difference is that, for the include () statement, it is read and evaluated every time the file is executed, whereas for require (), the file is processed only once (in fact, the file contents replace the Require () statement). This means that the use of require () is more efficient if the code can be executed more than once. On the other hand, if you are reading a different file each time you execute the code, or you have a loop that iterates through a set of files, use the Include () statement.

Require is used in the following way: Require ("myfile.php"), this statement is usually placed at the front of the PHP script. Before the PHP program executes, it will read into the file introduced by the Require () statement, making it part of the php script file. Include uses the same way as require: include ("myfile.php"), which is typically placed in the Process Control section. The php script file is read into the include () statement before the file it contains. This way, you can simplify the process of executing the program.

Incluce load when used

Require is loaded at the beginning

The _once suffix indicates that the load is not loaded

The PHP system has a pseudo-compile process when loading PHP programs, which can make the program run faster. However, the Incluce document is still interpreted for execution. Include file error, the main program continues to execute, require file error, the main program also stopped, so the inclusion of file errors on the system has little impact (such as interface files) with include, otherwise with require.

The Require () and include () statements are language constructs, not real functions, and can be like other language constructs in PHP, such as Echo () using echo ("AB"), or you can use echo "ABC" to output the string ABC. Require () and include () statements can also be directly added without parentheses.

The include_once () and require_once () statements also include running the specified file during script execution. This behavior is similar to the include () statement and require (), using the same method. The only difference is that if the code in the file is already included, it will not be included again. These two statements should be used in cases where the same file may be included more than once during script execution, ensuring that it is included only once to avoid problems such as function redefinition and variable re-assignment.

An explanation of the differences between include and require in PHP

Related Article

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.