从PHP脚本调用Java(或python或perl) [英] Calling Java (or python or perl) from a PHP script

查看:228
本文介绍了从PHP脚本调用Java(或python或perl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在Django中构建一个简单的原型应用程序,并且很遗憾,因为它太复杂了(我知道从长远来看它是值得的,但我确实只是没有足够的时间 - 我需要一些东西在几天内运行起来。所以,我现在正在考虑使用PHP,因为它是创建我最熟悉的动态Web内容的方法,而且我知道我可以快速完成某些工作。

I've been trying to build a simple prototype application in Django, and am reaching the point of giving up, sadly, as it's just too complicated (I know it would be worth it in the long-run, but I really just don't have enough time available -- I need something up and running in a few days). So, I'm now thinking of going with PHP instead, as it's the method for creating dynamic web content I'm most familiar with, and I know I can get something working quickly.

我的应用程序,虽然简单,可能会做一些相当复杂的AI的东西,并且可能是我不需要PHP中的库。所以我想知道PHP脚本调用Java程序或Python脚本或用另一种语言编写的程序或脚本是多么容易/可能。我并不完全清楚在这种情况下调用究竟是什么意思,但我想我可能意味着理想情况下我想定义一个函数,比如说Java,然后能够从PHP调用它。如果那是不可能的,那么我想我最好的选择(假设我选择PHP)将通过POST或GET直接将控制权直接传递给外部程序到CGI程序或类似程序。

My application, while simple, is probably going to be doing some reasonably complex AI stuff, and it may be that libraries don't exist for what I need in PHP. So I'm wondering how easy / possible it is for a PHP script to "call" a Java program or Python script or a program or script in another language. It's not entirely clear to me what exactly I mean by "call" in this context, but I guess I probably mean that ideally I'd like to define a function in, let's say Java, and then be able to call it from PHP. If that's not possible, then I guess my best bet (assuming I do go with PHP) will be to pass control directly to the external program explicitly through a POST or GET to a CGI program or similar.

随意说服我,我应该坚持使用Django,虽然我真的不知道我需要什么模型来生成我想要的HTML表单,这似乎是这样的基本的事情,我担心我有机会做更复杂的事情...

Feel free to convince me I should stick with Django, although I'm really at the point where I just can't figure out what model I need to produce the HTML form I want, which seems such a basic thing that I fear for my chances of doing anything more complex...

或者,任何能提供关于连接PHP和其他语言的建议的人,那都是感谢收到。

Alternatively, anyone who can offer any advice on linking PHP and other languages, that'll be grateful received.

推荐答案

我无法弄清楚我需要哪种模型来生成我想要的HTML表单,其中似乎是一件基本的事情,我担心我有机会做更复杂的事情

"where I just can't figure out what model I need to produce the HTML form I want, which seems such a basic thing that I fear for my chances of doing anything more complex"

常见问题。

根本原因:编程太多。

解决方案。少编程。说真的。

Solution. Do less programming. Seriously.

定义Django模型。使用默认管理页面查看是否正确。修复模型。重新生成数据库。查看默认管理页面。重复,直到默认管理页面正常且简单。

Define the Django model. Use the default admin pages to see if it's right. Fix the model. Regenerate the database. Look at the default admin pages. Repeat until the default admin pages work correctly and simply.

一旦在默认管理页面中正确,您就有了一个可行的模型。这是可以测试的。自动化的东西正确连接起来。选择是正确定义的。计算在模型中。查询工作。现在,您可以开始处理其他数据表示。

Once it's right in the default admin pages, you have a model that works. It's testable. And the automatic stuff is hooked up correctly. Choices are defined correctly. Computations are in the model mmethods. Queries work. Now you can start working on other presentations of the data.

Django通常以模型开始(并结束)。表单,视图和模板都是从模型中派生出来的。

Django generally starts (and ends) with the model. The forms, view and templates are derived from the model.

这篇关于从PHP脚本调用Java(或python或perl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆