Using activephp to build a version management System _php Tutorial

Source: Internet
Author: User
Tags learn php rar
When we learn PHP, we are always taught that PHP is a server-side script that cannot be used to control the client. And with the release of PHP5, this sentence is not so correct. Because now, PHP can also be used to write client script. Yes, you did not hear wrong, write client script in PHP.



Installation of activephp



Let's show you how to write client-side scripting using PHP. First of all, you need to download PHP5 installation package on Windows, and then extract it into a directory, such as: C:\Program files\easyphp5\php, then, enter the Windows command-line mode, CD to the directory you unzipped PHP5, and then type:

regsvr32 php5activescript.dll


After you enter, you will see a success prompt:




This means you can already use the activephp. Okay, so let's just write a simple script under test, still a global helloworld:p.










Save the top code as hello.htm, then double-click it and you'll see the results below.





php:5.0.0

Os:windows

Browser:ie





Well, the effect is good, but not enough to have the characteristics of the client. Let's modify the following code:










Run it again and see ~




Did you feel something?



Our Version management system



Let's go back and talk about the version management system. The version management system we are going to do is simple, which is to make a RAR package of the files in the development directory and the data tables of the database, named by time and placed in a backup directory. As the main purpose of this article is to demonstrate the use of activephp, we do not consider the management of RAR package and extract it to overwrite the original data content, but for a version of the management system, this part is very important, it is recommended that you complete;).





The MySQL database is stored as a file in the Mysql/data directory, and a library corresponds to a 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 and directly

System (' command ');


You can do it.



Then we need to know how to use RAR command line, this thing should certainly find help documentation, in the RAR installation directory. In the English heap for a long time, and finally found a method: To compress the file into a text file, and then the file name as a parameter, to RAR. Written as a command line is:

Rar.exe a path_to_save @file_list


Generating this file is very simple for PHP, a traversal function is available, and the bottom two functions are improved from the 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.

Below is the code for the actual operation section:





$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 (' shutting down the MySQL service process ... ');
System (' Mysqladmin.exe-uroot shutdown ');
R_walk ($mysql _path, $files);

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

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

$window->alert (' compression starts, do not manually close the cmd window ... ');
System (' Rar.exe a '. $bakeup _path. ' @ './info.txt "');

$window->alert (' compression complete, will restart MySQL, please manually close the cmd window that pops up below ... ');

Restart MySQL
System (' mysqld.exe& ');




The code above is simple, just a few places

· MySQL locks the data table at run time, so we need to stop the service before compressing, and then start after the compression is complete.

· The system command waits for the command to complete before continuing down, and Mysqld.exe is the background service, so the program goes to the waiting state and closes the cmd window manually.

· The path to the above RAR and MYSQLD programs is added to the environment variable, so do not specify. The place where Windows XP adds environment variables is in the system variable (Path), high-level environment variable, my Computer (right-click/properties).



OK, add the upper code, save, and then run the next look: very convenient, hoho~ article here, remember to finish the homework: P
(Source: Viphot)

http://www.bkjia.com/PHPjc/314051.html www.bkjia.com true http://www.bkjia.com/PHPjc/314051.html techarticle when we learn PHP, we are always taught that PHP is a server-side script that cannot be used to control the client. And with the release of PHP5, this sentence is not so correct. Because now ...

  • 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.