开发者

How can I use SVN functions within PHP?

I'm a new to SVN and trying to manipulate it through PHP. I tried using popen() to execute SVN calls directly to no avail.

I found this module on php.net which has methods to manage SVN within PHP.

So, how do I install and configure this modu开发者_开发知识库le?


If you use Ubuntu (or maybe another Debian-based OS), you can install this very easily by running the following commands:

sudo apt-get install php5-svn
sudo /etc/init.d/apache2 restart

If it installed and Apache restarted smoothly, you should be able to use any of the SVN functions listed in PHP's docs!

To get you started, here's a PHP script which updates the repo in the current directory

svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, 'yourUserName');
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, 'yourPassword');
$b4 = trim(`svnversion`);
if ($revision = svn_update(realpath(getcwd()))) { //use @svn_update(...) if you want to hide warnings
    if ($b4 === trim(`svnversion`)) {
        echo 'Already up-to-date (r'.$b4.').';
    } else {
        echo 'Updated to r'.$revision;
    }
} else {
    echo 'Update failed';
}


What operating system are you working on? SVN will work the same no matter what language you are working with. Just find the a good tool for your platform.

Windows

  • TortoiseSVN - One of the best SVN tool kits around.

If you are asking about how to control and SVN respoitory from PHP then you should just read up on the docs. I found a more detailed manual on doc.php.net


http://www.php.net/manual/en/svn.installation.php

http://www.php.net/manual/en/install.pecl.pear.php

On *nix, try pecl install svn on the command line.

If PECL doesn't work, try yum install php-devel


... on CentOS 7.0 one can install it like that:

install prerequisites:

yum install php-devel subversion-devel php-pear

download php-svn and build it:

pecl install svn

add the config file:

echo "extension=svn.so" > /etc/php.d/svn.ini

restart HTTPd:

/bin/systemctl restart httpd.service
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜