Home Backend Development PHP Tutorial Use ActivePHP to build a version management system_PHP tutorial

Use ActivePHP to build a version management system_PHP tutorial

Jul 21, 2016 pm 04:11 PM
php No study us build hour yes server Version use end management system Script


When learning PHP, we are always taught that PHP is a server-side script and cannot be used to control the client. With the release of PHP5, this sentence is not so correct. Because now, PHP can also be used to write client-side scripts. Yes, you heard it right, write client scripts in PHP.



ActivePHP installation



Now we will demonstrate how to use PHP to write client scripts. First, you need to download the PHP5 installation package on Windows, and then unzip it to a directory, such as: C:Program FilesEasyPHP5php. Then, enter the command line mode of Windows, cd to the directory where you unzipped PHP5, and then type:

regsvr32 php5activescript.dll


After pressing Enter, you will see a success prompt:




This means you can already use it ActivePHP. Okay, let's write a simple script to test it. It is still a universal HelloWorld:P.










Save the above code as Hello.htm, then double-click it, you can see the result below.





PHP: 5.0.0

OS: Windows

Browser: IE





Well, the effect is good, but it is not client-side enough. Let's modify the code:










Run it again and see~




Do you feel something?



Our version management system



Let’s go back and talk about the version management system. The version management system we want to build is very simple. It is to package the files in the development directory and the data tables of the database into a RAR package, name it according to time and put it in a backup directory. Since the main purpose of this article is to demonstrate the use of ActivePHP, we will not consider the management of RAR packages and the content of decompressing them to overwrite the original data. However, for a version management system, this part is very important. We recommend that you Do it yourself ;).





Mysql database is stored in the mysql/data directory in the form of files, and one library corresponds to one directory.




First we need to know how PHP calls other programs on Windows, which is the System command. This command is as simple as Echo, just

System('command');


.



Then we need to know how to use the command line of RAR. For this kind of thing, of course you should find the help document, which is in the installation directory of RAR. After looking at the English pile for a long time, I finally found a method: write the file to be compressed into a text file, and then pass the file name as a parameter to RAR. Written as a command line:

rar.exe a path_to_save @file_list


Generating this file is very simple for PHP, just a traversal function, the following two functions are Improved from User Contribute in the PHP manual.





function R_walk($oldname, &$string)
{
if(is_file($oldname) )
{
$string .= $oldname ."rn";
}
else if(is_dir ( $oldname ) )
{
R_dir_walk($oldname, $string) ;
}
else
{
die("Cannot add file: $oldname (it's neither a file nor a directory)");
}
}

function R_dir_walk($oldname, &$string)
{
$dir = opendir( $oldname );
while( $file = readdir( $dir ) )
{
if ( $file == "."
$file == ".." )
{
continue;
}

R_walk("$oldname/$file", $string );
}
closedir($dir);
}




With these two functions, it is easy to generate a list file.

The following is the code for the actual operation:





$php_path = 'C:/Program Files/ EasyPHP1-7/home/dev/R4/';
$mysql_path = 'C:/Program Files/EasyPHP1-7/mysql/data/r4/';

$date = date( "Y_m_d_H_i_s " );
$bakeup_path = 'D:/bakeup/R4/Backup_'.$date;

// copy file
R_walk( $php_path , $files );

// stop mysql
$window->alert( 'Mysql service process is about to be shut down...' );
system( 'mysqladmin.exe -uroot shutdown' );
R_walk( $mysql_path , $ files );

$files = str_replace( '/' , '\' , $files );

write2_file( './info.txt' , $files );

$window->alert( 'Compression starts, please do not close the CMD window manually...' );
system( 'rar.exe a "' . $bakeup_path . '" @"./info.txt" ' );

$window->alert( 'Compression completed, Mysql will be restarted soon, please manually close the CMD window that pops up below...' );

// restart mysql
system( 'mysqld.exe&' );




The above code is very simple and only explains a few places

· Mysql will lock the data table when running , so we need to stop the service before compression and start it again after compression is completed.

· System command will wait for the command to be completed before continuing to execute. Mysqld.exe is a background service and will not stop, so the program will enter the waiting state here. Just close the CMD window manually. .

· The paths of programs such as rar and mysqld above are added to the environment variables, so there is no need to specify them. The place to add environment variables in Windows XP is: My Computer (right click/Properties) -> Advanced -> Environment Variables -> System Variables (Path).



Okay, add the above code, save it, and run it again: it’s very convenient, HoHo~ That’s it for the article, remember to finish your homework :P
( Source: Viphot)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314051.htmlTechArticleWhen learning PHP, we are always taught that PHP is a server-side script and cannot be used to control client side. With the release of PHP5, this sentence is not so correct. Because now...
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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Services CakePHP Services Sep 10, 2024 pm 05:26 PM

This chapter deals with the information about the authentication process available in CakePHP.

See all articles