国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開發(fā) Summary of methods for generating HTML pure static web pages from the entire website using PHP

Summary of methods for generating HTML pure static web pages from the entire website using PHP

Dec 21, 2016 am 11:25 AM

The example in this article describes the implementation method of multi-thread concurrency in PHP. Share it with everyone for your reference, the details are as follows:

Multi-threading in Java is a new thread thing. PHP relies on Apache and there is a multi-threading method at the bottom of Linux.

Here is how to simulate PHP concurrency if you cannot control the Apache server

<?php
if(function_exists(&#39;date_default_timezone_set&#39;)) {
  date_default_timezone_set(&#39;PRC&#39;);
}
function a()
{
 $time = time();
 sleep(3);
 $fp = fopen(&#39;result_a&#39;.$time.&#39;.log&#39;, &#39;w&#39;);
 fputs($fp, &#39;Set in &#39; . Date(&#39;h:i:s&#39;, time()) . (double)microtime() . "rn");
 fclose($fp);
}
function b()
{
 $time = time();
 sleep(3);
 $fp = fopen(&#39;result_b&#39;.$time.&#39;.log&#39;, &#39;w&#39;);
 fputs($fp, &#39;Set in &#39; . Date(&#39;h:i:s&#39;, time()) . (double)microtime() . "rn");
 fclose($fp);
}
if(!isset($_GET[&#39;act&#39;])) $_GET[&#39;act&#39;] = &#39;a&#39;;
if($_GET[&#39;act&#39;] == &#39;a&#39;)
{
 a();
}
else if($_GET[&#39;act&#39;] == &#39;b&#39;) b();
?>

The above code writes a file locally.

If you visit localhost/a.php and open two browser tabs at the same time as quickly as possible, you will find that the difference in creation time of the two files is 3 seconds

But if you visit localhost/a.php?act=b another one Visit /a.php?act=a and you will find that the two files were created at almost the same time.

For apache, the same URL means a thread (or process), but different URLs mean concurrency.

If there is a download action inside php

function runThread()
{
 down("http://localhost/test/a.php?act=a");
}
if($_GET[&#39;act&#39;] == &#39;run&#39;)
{
 echo &#39;start:&#39;;
 runThread();
 echo &#39; End&#39;;
}

http://localhost/test/a.php?act=run

http://localhost/test/a.php?act=run&s=2

As long as the host If the accessed URLs are different, they are considered to be different processes, which means concurrency. The file creation time is not 3 seconds

Friends who have a local Linux server can also use Linux to simulate concurrency

<?php
for ($i=0;$i<10;$i++) {
echo $i;
sleep(5);
}
?>

Save the above as test.php, and then write a SHELL code

#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10
do
php -q test.php &
done


More PHP will convert the entire website For a summary of methods for generating pure static HTML web pages, please pay attention to the PHP Chinese website for related articles!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276