为PHP增加SVN扩展,不让PHP退出的启动方法:/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf --pid /usr/local/php/var/run/php-fpm.pid 。

jackxiang 2012-2-28 15:40 | |
   最近的一个项目需要PHP与SVN交互,最先想到的解决方案是用PHP的SVN扩展,搜了已经有PHP的SVN扩展,这两天也去http:/pecl.php.net/package/svn 上面下载了SVN扩展的源码.【备注:比如我看到php的subversion扩展是有的, 不过手册里写的却是试用阶段. 应该不如python的成熟. 何况...我觉得这种事情确实应该让python干, 就像web的事情应该让php干一样.http:/blog.csdn.net/akara/article/details/5566524】

为PHP增加SVN扩展:
http:/www.swordair.com/blog/2010/01/85


Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/ successed
至此,终于通过编译,并在完成的最后提示在php.ini中增加一行:

版本比较差异,这样导出差异文件,后覆盖线上即可:
svn diff -r m:n path(对版本m和版本n比较差异)
例如:svn diff -r 200:201 test.php
简写:svn di

svn diff -r 版本号1:版本号2  工作拷贝文件地址 >  保存差异文件
例:
svn diff -r PREV:COMMITTED  ./project/trunk/helloworld.c  > patch.c
写一个脚本测试一下,成功。
----------------------------------------------------------------------------------------------------
svn diff 比较两个目录:
svn diff --summarize http://rep_url/tags/proj1_090214 http://rep_url/trunk/proj1 >diff.txt
这个命令比较了 proj1_090214 和 proj1 的差异,并将差异信息输出到文件 diff.txt
summarize   选项的含义是只显示结果的概要,不显示文件的具体差异。
---------------------------------------------------------------------------------------------------
这样也成:
svn diff -r 3797:3788 --summarize https://tc-svn.XXXX.com/web/CCCC/web_aXc_proj/trunk  








下面是给svn设置用户名密码来访问,特别是ssl这块否则在终端是可以的,但是在apache加载后会报错:


通过svn list 导出该目录下所有的文件。
svn list -R  http:/192.168.1.11/svn/reponame/J2EE11 | wc -l

http:/192.168.1.11/svn 是 svn server 的root  /reponame 是库 /J2EE11 是路径

这样会包括 目录

过滤目录
svn list -R  svn_server_addr/svnrepo/folder  | grep -v \/$ | wc -l

请在 linux 下运行 win 平台可以装cygwin .
获取目录的函数实践:

查询版本下的注释:

Please not that using svn_log without giving revisions is much, much slower then with revisions. Examples:

$ time php -r "svn_log('http://localhost/svn/shopadsl');"

real    0m2.140s
user    0m0.140s
sys     0m0.000s

VS

$ time php -r "svn_log('http://localhost/svn/shopadsl', 0, 45);"

real    0m0.063s
user    0m0.024s
sys     0m0.016s

默认svn在linux下的密码位置参考:http:/jackxiang.com/post/4512/

更多使用方法:http:/www.php.net/manual/en/function.svn-checkout.php
重启Apache
[plain] view plaincopy
/etc/init.d/apache2 reload  
或php-fpm 重启:
[plain] view plaincopy
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`  

发现在Apache启动后会报错,解决方法如下:
If you having trouble with certificate verification like this:

PHP Warning:  svn_log(): svn error(s) occured 175002 (RA  layer request failed) OPTIONS of 'https://example.com/your/repos/path': Server certificate verification failed: issuer is not trusted

Try this two steps:

1. Run

"svn log https://example.com/your/repos/path"

on the commandline and permanent accept the certificate by typing "p" when asked.

2. Use the following settings for svn_auth_set_parameter() before calling other svn functions:


当然,也可以直接用PHP的Popen:
popen()这个函数, 看来echo t | svn ci ...那些命令可以用另外的方式来解决了

附转:

popen()函数打开一个进程管道来执行给定的命令,返回一个文件句柄。既然返回的是一个文件句柄,那么就可以对它读和写了。在PHP3中,对这种句柄只能做单一的操作模式,要么写,要么读;从PHP4开始,可以同时读和写了。除非这个句柄是以一种模式(读或写)打开的,否则必须调用pclose()函数来关闭它。


常用操作
1.查看最近3个版本日志
svn log [PATH] -v -l3

2.查看某两个版本,用来对比
svn log -r 14:15

3.日志放入文件
$ svn log -r 14 > mylog
$ svn log -r 19 >> mylog
$ svn log -r 27 >> mylog
$ cat mylog

或者
$ svn log –incremental -r 14 > mylog
$ svn log –incremental -r 19 >> mylog
$ svn log –incremental -r 27 >> mylog
$ cat mylog

参考:http:/www.php.net/manual/en/function.svn-checkout.php
你也可以参考:http:/blog.csdn.net/dragon8299/article/details/6689685
http:/www.swordair.com/blog/2010/01/85
http:/biancheng.dnbcw.info/win2003/377268.html


如果configure报下面的错
checking for svn includes... configure: error: failed to find svn_client.h
安装libsvn-dev包:CentOs应该也有对应的包
apt-get install libsvn-dev


解压缩后 切换到安装目录 执行/opt/lamp/php/bin/phpize
然后:./configure –with-php-config=/opt/lamp/php/bin/php-config
出现错误:checking for svn includes… configure: error: failed to find svn_client.h
解决办法:添加subversion服务端的目录 –with-svn=/usr/local/subversion
./configure –with-php-config=/opt/lamp/php/bin/php-config  –with-svn=/usr/local/subversion

make出错:
/usr/bin/ld: cannot find -lsvn_client-1

ok




===================================================================
在Tlinux的64位机器上折腾步骤记录,我艹,比Cenots折腾了更多时间来整这个玩意,真是步步惊心啊,如下:
第一步:编译,参数如下 ,这个参数都折腾了老半天啊。
./configure --with-php-config=/usr/local/qqwebsrv/php/bin/php-config  --with-svn=/opt/CollabNet_Subversion --with-svn-apr=/usr/local/apr
中间就会提示找不到什么.h啊:checking for svn includes... configure: error: failed to find svn_client.h,于是得找个这个h的包放在里面去才行。
root@10.12.21.108:~/software/svn-1.0.2# ls /usr/local/include/
subversion-1  subversion-1.tar.gz

第二步:/usr/local/apr-util/include/apr-1 这个Include进Makefile里。
修改Makefile: 39行左右
39 INCLUDES = -I/usr/local/qqwebsrv/php/include/php -I/usr/local/qqwebsrv/php/include/php/main -I/usr/local/qqwebsrv/php/includ        e/php/TSRM -I/usr/local/qqwebsrv/php/include/php/Zend -I/usr/local/qqwebsrv/php/include/php/ext -I/usr/local/qqwebsrv/php/in        clude/php/ext/date/lib -I/usr/local/include/subversion-1 -I/usr/local/apr/include/apr-1 -I/usr/local/apr-util/include/apr-1         -DLINUX=2 -D_REENTRANT -D_GNU_SOURC
加入:/usr/local/apr-util/include/apr-1
-I/usr/local/apr/include/apr-1 -I/usr/local/apr-util/include/apr-1

第三步:出现老是什么 cannot find -lsvn_client-1  ,做软链接后,出现下一个,太多了,于是否,如下:
全拷贝过去得了,注意:/opt/CollabNet_Subversion 这个是在网上找的整个包进行安装的SVN,是Rpm包。
cp -Rf /opt/CollabNet_Subversion/lib/*  /usr/lib/
make
make install
root@10.12.22.108:~/software/svn-1.0.2# make install
Installing shared extensions:     /usr/local/qqwebsrv/php/lib/extensions/


第四步:因发现在加入这个扩展后,出现:libsvn_client-1.so.0 cannot open shared object file no such file or directory
root@10.12.22.108:/# /sbin/ldconfig
/sbin/ldconfig: libraries libsasl2.so.2.0.21 and libsasl2.so.2.0.23 in directory /usr/lib have same soname but different type.
/sbin/ldconfig: libraries libgz.so.1 and libz.so.1.2.5 in directory /usr/lib have same soname but different type.
ldconfig: /usr/lib/libsvn_client-1.so.0 is not a symbolic link
根据上面的提示,于是删除掉这个文件:
rm -Rf  /usr/lib/libsvn_client-1.so.0
上面两个不管它,就这样就好了。

第五步(经实践是多余的):
查找网上文章:http://www.cnblogs.com/amboyna/archive/2008/02/06/1065322.html
vi /etc/ld.so.conf
加上:

再运行这个PHP的SVN扩展,好了。前面的libsasl2,libgz,删除高版本的,做个软链接就Ok了。

但是TLamp有问题了,Apache出现了:
[codes=html]
Apache2 has detected a syntax error in your configuration files:
apache2: Syntax error on line 142 of /etc/apache2/httpd.conf: Cannot load /usr/lib64/apache2/modules/mod_ssl.so into server: /usr/lib64/apache2/modules/mod_ssl.so: undefined symbol: SSL_CTX_set_client_cert_cb
[codes=html]
于是,自己重新下了一个Apache,PHP5.3.11等,重新编译后,这个问题也就没有了,直接访问SVN扩展输出Ok了,还以为需要用system或者popen去打开呢,看来用不着了。

为了安全把一些函数都给屏蔽了,在php.ini里可以看到:
[codes=html]
disable_functions = passthru,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,system,exec
[codes=html]
因只为了这个svn扩展,PHP5.3.11的编译也很简单,如下:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd-2.0.59/bin/apxs   --enable-sockets --enable-mbstring

原本想加入其它的,现在想来,没有必要加上什么Mysql,Pdo,Mbstring等等。
(./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd-2.0.59/bin/apxs  --with-pdo=shared --with-pdo-mysql=/usr/local/mysql --enable-sockets --enable-mbstring)

EOF

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/5028/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2019-12-31 13:48
评论列表
2012-3-23 08:30 | ahcznkyy Email Homepage
新手学习中,谢谢楼主分享!!!
分页: 1/1 第一页 1 最后页
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]