Heim  >  Artikel  >  Backend-Entwicklung  >  PHP结合Python语言开发网站

PHP结合Python语言开发网站

WBOY
WBOYOriginal
2016-06-20 13:02:021809Durchsuche

如何在PHP代码中执行Python,我们一般是通过php的exec或者system来执行命令。其实还可以通过socket通信调用python。

可以参考这里,

http://code.google.com/p/ppython/

https://github.com/GoldenAges/ppython

其实思路是很简单的。

这个简单的ppython可以让PHP调用Python代码,诱惑力还是相当的大的,用作者的话来说是结合使用PHP和Python两种语言,取其所长、补其所短,面向企业WEB领域的开发技术。

此技术可以理解为PHP和Python相结合的技术,也可称为PHP和Python混合编程技术,或者PHP调用Python服务的技术,也有人习惯称之为前台PHP后台Python的技术框架。

代码也很简洁,将调用Python的模块,函数,参数等序列化,通过socket发送给Python,然后Python反序列化后通过exec执行获取结果,并把结果发送出去。

上面代码时运行在python3.x上的,平时开发是python2.x,代码移植到python2.x上,主要就是两点:

1.异常 python3.x 使用as关键字

2.python3.x 将str和byte分开了 

 

 


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn