When learning PHP, we are always taught that PHP is a server-side script that cannot be used to control clients. And along 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 correctly, write client script in PHP.
Installation of activephp
Let's show you how to write client script using PHP. First, you need to download the PHP5 installation package on Windows, and then extract it into a directory, such as: C:\Program files\easyphp5\php, then, enter the command line mode of Windows, CD to the directory you unzipped PHP5, and then type:
regsvr32 php5activescript.dll
When you enter, you will see a success note:
This means you can already use activephp. OK, let's write a simple script that is still the global helloworld:p.
Here we go back to say version management system. Our version management system is very simple, that is, the development directory of files and database tables into a RAR package, named after the time and put in a backup directory. Because the main purpose of this article is to demonstrate the use of activephp, we do not consider the RAR package management and decompression of the content of the original data, but for a version management system, this part is very important, we recommend that everyone to complete;
? Related Knowledge?>
The MySQL database is stored in the Mysql/data directory as a file, 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, directly
System (' command ');
It's OK.
Then we need to know the command line usage of RAR, this kind of thing should certainly find the help document, in the RAR installation directory. Read in the English heap for a long time, finally found a way: to compress the file into a text file, and then the filename as a parameter, passed to RAR. Written as a command line is:
Rar.exe a path_to_save @file_list
To generate this file for PHP is very simple, a traversal function on it, the bottom of these two functions are from the PHP manual user Contribute improved.
? Code List?>
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
}
Stop MySQL
$window->alert (' Impending shutdown of the MySQL service process ... ');
System (' Mysqladmin.exe-uroot shutdown ');
R_walk ($mysql _path, $files);
$files = Str_replace ('/', ' \ n ', $files);
Write2_file ('./info.txt ', $files);
$window->alert (' compression begins, please do not manually close the cmd window ... ');
System (' Rar.exe a '. $bakeup _path. "@"./info.txt "');
$window->alert (' compression complete, is about to restart MySQL, please manually close the pop-up cmd window below ... ');
Restart MySQL
System (' mysqld.exe& ');
The code above is simple, just a few places.
· MySQL locks the datasheet at run time, so we have to stop the service before we compress it and then start it after the compression is complete.
· The system command waits for the command to complete and then continues down, and Mysqld.exe is the background service, it will not stop, so the program is here to enter the waiting state, manually close the cmd window can be.
· The paths of the above RAR and MYSQLD programs are added to environment variables, so you do not need to specify them. Where Windows XP adds environment variables: My Computer (right key/properties)-> Advanced-> environment variable-> system variable (Path).
Well, add the above code, save, and then run the next look: very convenient, hoho~ article is here, remember to finish the homework: P
(Source: Viphot)
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.