


Asynchronous execution of scripts in PHP language_PHP tutorial
PHP language implements asynchronous execution of scripts
In PHP language, you need to use the fsockopen() function to run the script asynchronously. The code is as follows//Asynchronous request function (if the debug parameter is true, it is used for debugging. If you enable debugging, you can see the asynchronous execution, but the asynchronous effect will be lost)
main.php
<!--?php function request_by_fsockopen($url,$post_data=array(),$debug=false){ $url_array = parse_url($url); $hostname = $url_array['host']; $port = isset($url_array['port'])? $url_array['port'] : 80; @$requestPath = $url_array['path'] ."?". $url_array['query']; $fp = fsockopen($hostname, $port, $errno, $errstr, 10); if (!$fp) { echo "$errstr ($errno)"; return false; } $method = "GET"; if(!empty($post_data)){ $method = "POST"; } $header = "$method $requestPath HTTP/1.1\r\n"; $header.="Host: $hostname\r\n"; if(!empty($post_data)){ $_post = strval(NULL); foreach($post_data as $k =--> $v){ $_post[]= $k."=".urlencode($v);//必须做url转码以防模拟post提交的数据中有&符而导致post参数键值对紊乱 } $_post = implode('&', $_post); $header .= "Content-Type: application/x-www-form-urlencoded\r\n";//POST数据 $header .= "Content-Length: ". strlen($_post) ."\r\n";//POST数据的长度 $header.="Connection: Close\r\n\r\n";//长连接关闭 $header .= $_post; //传递POST数据 }else{ $header.="Connection: Close\r\n\r\n";//长连接关闭 } fwrite($fp, $header); //-----------------调试代码区间----------------- //注如果开启下面的注释,异步将不生效可是方便调试 if($debug){ $html = ''; while (!feof($fp)) { $html.=fgets($fp); } echo $html; } //-----------------调试代码区间----------------- fclose($fp); } $data=array('name'=>'guoyu','pwd'=>'123456'); $url='http://localhost/test/other.php'; request_by_fsockopen($url,$data,true);//
other.php
<!--?php header("content-type:text/html;charset=utf-8"); //error_reporting(0); //ini_set('html_errors',false); //ini_set('display_errors',false); $name = isset($_POST['name'])?$_POST['name']:''; $pwd = isset($_POST['pwd'])?$_POST['pwd']:''; echo $name.$pwd; echo 'success ok'; die; ?-->
Usage example:
[main.php main script file to run]
$data=array('name'=>'guoyu','pwd'=>'123456');
$url='http://localhost/test/other.php';
request_by_fsockopen($url,$data,true);//Asynchronously-synchronize the user table of application B
[Guide execution file other.php]
In other.php, you can use $_POST to receive the parameters submitted by main.php to proceed with the next step

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Work on the same setup for too long or share your PC with others. You may have some language packs installed, which often create conflicts. So, it’s time to remove unwanted display languages in Windows 11. Speaking of conflicts, when there are multiple language packs, inadvertently pressing Ctrl+Shift changes the keyboard layout. If not taken care of, this can be a hindrance to the task at hand. So, let’s jump right into the method! How to remove display language from Windows 11? 1. From Settings press + to open the Settings app, go to Time & Language from the navigation pane and click on Language & Region. WindowsI click the ellipsis next to the display language you want to remove and select Remove from the pop-up menu. Click "

Cutting is a video editing tool with comprehensive editing functions, support for variable speed, various filters and beauty effects, and rich music library resources. In this software, you can edit videos directly or create editing scripts, but how to do it? In this tutorial, the editor will introduce the method of editing and making scripts. Production method: 1. Click to open the editing software on your computer, then find the "Creation Script" option and click to open. 2. In the creation script page, enter the "script title", and then enter a brief introduction to the shooting content in the outline. 3. How can I see the "Storyboard Description" option in the outline?

Automation and task scheduling play a vital role in streamlining repetitive tasks in software development. Imagine there is a Python script that needs to be executed every 5 minutes, such as getting data from an API, performing data processing, or sending periodic updates. Running scripts manually so frequently can be time-consuming and error-prone. This is where task scheduling comes in. In this blog post, we will explore how to schedule a Python script to execute every 5 minutes, ensuring it runs automatically without manual intervention. We will discuss different methods and libraries that can be used to achieve this goal, allowing you to automate tasks efficiently. An easy way to run a Python script every 5 minutes using the time.sleep() function is to utilize tim

In today's fast-paced digital world, being able to automate computer tasks can greatly increase productivity and convenience. One of the tasks is shutting down the computer, which can be very time-consuming if done manually. Thankfully, Python provides us with a powerful set of tools to interact with the system and automate such tasks. In this blog post, we will explore how to write a Python script to shut down your computer easily. Whether you want to schedule an automatic shutdown, remotely initiate a shutdown, or simply save time by avoiding a manual shutdown, this script will come in handy. Importing the Required Modules Before we start writing the script, we need to import the necessary modules in order to interact with the system and execute the shutdown command. In this section we will import the os module (which

How to execute .sh file in Linux system? In Linux systems, a .sh file is a file called a Shell script, which is used to execute a series of commands. Executing .sh files is a very common operation. This article will introduce how to execute .sh files in Linux systems and provide specific code examples. Method 1: Use an absolute path to execute a .sh file. To execute a .sh file in a Linux system, you can use an absolute path to specify the location of the file. The following are the specific steps: Open the terminal

It's no secret that the iPhone is one of the most user-friendly electronic gadgets, and one of the reasons why is that it can be easily personalized to your liking. In Personalization, you can change the language to a different language than the one you selected when setting up your iPhone. If you're familiar with multiple languages, or your iPhone's language setting is wrong, you can change it as we explain below. How to Change the Language of iPhone [3 Methods] iOS allows users to freely switch the preferred language on iPhone to adapt to different needs. You can change the language of interaction with Siri to facilitate communication with the voice assistant. At the same time, when using the local keyboard, you can easily switch between multiple languages to improve input efficiency.

Restarting your computer is a common task that we often perform to troubleshoot problems, install updates, or apply system changes. While there are many ways to restart your computer, using a Python script provides automation and convenience. In this article, we will explore how to create a Python script that can restart your computer with a simple execution. We will first discuss the importance of restarting your computer and the benefits it brings. We will then delve into the implementation details of the Python script, explaining the necessary modules and functionality involved. Throughout this article, we will provide detailed explanations and code snippets to ensure clear understanding. Importance of Restarting Your Computer Restarting your computer is a basic troubleshooting step that can

We've designed this Windows PowerShell scripting tutorial for beginners, whether you're a tech enthusiast or a professional looking to improve your scripting skills. If you have no prior knowledge of PowerShell scripting, this article will start with the basics and be tailored for you. We'll help you master the installation steps for a PowerShell environment and walk you through the main concepts and features of PowerShell scripts. If you're ready to learn more about PowerShell scripting, let's embark on this exciting learning journey together! What is WindowsPowerShell? PowerShell is a hybrid command system developed by Microsoft
