开发者

Python PHP and Perl being used together?

开发者 https://www.devze.com 2023-03-23 15:52 出处:网络
I was reading through Facebook\'s hiring now job listings and I saw this... *Competency in Shell, PHP, Perl or Python. C is a plus

I was reading through Facebook's hiring now job listings and I saw this...

* Competency in Shell, PHP, Perl or Python. C is a plus

This sparked a question in my mind, is it possible to use (for example) python and PHP together?

As in... I write a function in PHP to read a MySQL database and cut the data read into raw string form.

I then use python to use this PHP function to perform operations on this data.

The part where I say "use python to use this PHP function" is this possible?

If so, how? (a small code example wou开发者_运维知识库ld be awesome)


First, Facebook is a large company. They have many different software projects, apart from the site itself, and some of them are probably written in languages different from the company's mainstream.

Second, teaching a good $lang1 programmer $lang2's syntax takes two weeks, while teaching a bad $lang2 programmer how to program takes life.


Although it's possible to mix all of this stuff together, it makes no sense at all to do it deliberately. My guess is they have the average Whitman's Sampler of scripts lying around, written by whomever, whenever, and in whatever language they felt like using. It's a bit of a legacy nightmare, but you don't just chop working code. Most shops eventually prune things back to one or two languages and drop the rest.


I think there are two answers.

The simple answer to this question is to use the exec() function in your PHP scripts to execute python scripts.

There is also the complicated answer, to either build, or use a prior attempted PHP extension PiP:

this extensions allows the Python interpretter to be embedded inside of PHP (think of PHP as the parent language with Python as its child). This allows native Python objects to be instantiated and manipulated from within PHP. There is also initial support for accessing PHP functions and data from within the embedded Python

I'd love to see some examples of it in use.

0

精彩评论

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