PHP脚本与C / C ++程序通信 [英] PHP script communicating with C/C++ program

查看:71
本文介绍了PHP脚本与C / C ++程序通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这个帖子属于哪个论坛,所以我已经把它发布给了我认为合适的几个论坛。


在给我建议时,请认为我是初学者。以下是我的问题/问题的概要



一些背景:

- 我正在编写基于php的Web应用程序。

- 我需要完成一项数据密集型任务,需要

读取和查找大量数据。

- 这个数据全部存储在数据库中。如果我直接从php进行了计算

,那么数据库上的负载过于密集,并且

需要不可接受的时间(超过20秒)来计算(我已经试过这个了吗。

- 所以我想我需要做的就是将所有这些数据加载到内存中,

然后从那里做这个操作,这比在数据库上查找要快得多。


我想做什么:

- 编写一个持续运行的C / C ++程序专用

进行数据密集型操作。

- 该程序将读取所有

加载后,从dbase到内存的数据。然后它将从PHP脚本请求对该数据运行

操作并将结果返回给PHP脚本。


我想要的东西查看:

- 我知道你可以用C ++编写PHP扩展

http://bugs.tutorbuddy.com/php5cpp/php5cpp/ )但我不知道这是不是这个

是什么我想这样做是因为(据我所知),一个扩展名是

加载和卸载脚本。我需要的C ++程序必须是

在后台不断运行,接收请求并返回

结果。


如果有人有任何建议我如何编写这个c / c ++

程序与php脚本进行通信或做类似的事情,

我将不胜感激任何帮助。 (即使你认为我使用了错误的

技术来实现这一点,我想知道)谢谢!


PS-我目前apache / php / mysql安装在Windows中,但是当这个

项目上线时,我希望它能在unix中运行。

Hi, I wasn''t sure which forum this post belongs to, so I''ve posted it
to a couple forums that I thought may be appropriate.

In giving me advice, please consider me a beginner. Below is a synopsis
of my problem/question:

SOME BACKGROUND:
- I am writing a php based web application.
- There is a very data intensive task I need to do that requires
reading and lookup of a lot of data.
- This data is all stored in a database. If I did the computation
directly from php, then the load on the database is too intensive, and
takes a unacceptable amount of time (over 20 secs) to calculate (I''ve
already tried this).
- So I thought what I need to do is load all this data into memory,
and then do this operation from there, and this should be a lot faster
than doing lookups on a database.

WHAT I WANT TO DO:
- Write a C/C++ program that is constantly running that is dedicated
to doing this data intensive operation.
- This program would read all the data from the dbase into memory upon
load. Then it would take requests from a PHP script to run the
operation on that data and return the results to the PHP script.

THINGS I''VE LOOKED INTO:
- I know you can write extensions to php in C++
(http://bugs.tutorbuddy.com/php5cpp/php5cpp/) but I don''t know if this
is what I want to do because (as far as I understand) an extension is
loaded and unloaded with the script. The C++ program I need has to be
constantly running in the background, taking requests and returning
results.

If anyone has any advice of how I can go about writing this c/c++
program that communicates with a php script or doing something similar,
I would appreciate any help. (even if you think I am using the wrong
technology to accomplish this, I''d like to know) Thank you!

PS- my current apache/php/mysql setup is in Windows, however when this
project goes live, I expect it to be running in unix.

推荐答案

2005-08-17,Nimit< ni ******** @ gmail.com>写道:
On 2005-08-17, Nimit <ni********@gmail.com> wrote:
- 我正在编写一个基于php的Web应用程序。
- 我需要做一个非常数据密集的任务,需要阅读和查找大量数据。
- 此数据全部存储在数据库中。如果我直接从php进行计算,那么数据库上的负载过于密集,并且需要花费不可接受的时间(超过20秒)来计算(我已经
已经尝试了这个。)
- 所以我认为我需要做的是将所有这些数据加载到内存中,然后从那里执行此操作,这应该比它快得多在数据库上进行查找。
- I am writing a php based web application.
- There is a very data intensive task I need to do that requires
reading and lookup of a lot of data.
- This data is all stored in a database. If I did the computation
directly from php, then the load on the database is too intensive, and
takes a unacceptable amount of time (over 20 secs) to calculate (I''ve
already tried this).
- So I thought what I need to do is load all this data into memory,
and then do this operation from there, and this should be a lot faster
than doing lookups on a database.




为什么你认为你的自定义?数据库程序的表现会比为这些东西优化的产品好吗?


将另一个从属数据库服务器投入到其中的成本是多少/>
执行你的php查询?你需要花多少时间来写自己的程序?
?这段时间值多少钱?


-

遇见vriendelijke groeten,

Tim Van Wassenhove< http ://timvw.madoka.be>



Why do you think your "custom" database program will perform better than
a product that has been optimised for this stuff?

How much does it cost to throw in another slave database server to
perform your php queries on? How much time to do you expect it to take
to write your own program? And how much is that time worth to you?

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>


Nimit写道:

在给我建议时,请认为我是初学者。以下是我的问题/问题的概要:

一些背景:
- 我正在编写一个基于php的Web应用程序。
- 有一个非常数据密集型我需要做的任务需要读取和查找大量数据。
- 这些数据都存储在数据库中。如果我直接从php进行计算,那么数据库上的负载过于密集,并且需要花费不可接受的时间(超过20秒)来计算(我已经
已经尝试了这个。)
- 所以我认为我需要做的是将所有这些数据加载到内存中,然后从那里执行此操作,这应该比它快得多在数据库上进行查找。

我想做什么:
- 编写一个持续运行的C / C ++程序,专门用于执行此数据密集型操作。
- 该程序将在加载时将dbase中的所有数据读入内存。然后它将从PHP脚本请求对该数据运行
操作并将结果返回给PHP脚本。

In giving me advice, please consider me a beginner. Below is a synopsis
of my problem/question:

SOME BACKGROUND:
- I am writing a php based web application.
- There is a very data intensive task I need to do that requires
reading and lookup of a lot of data.
- This data is all stored in a database. If I did the computation
directly from php, then the load on the database is too intensive, and
takes a unacceptable amount of time (over 20 secs) to calculate (I''ve
already tried this).
- So I thought what I need to do is load all this data into memory,
and then do this operation from there, and this should be a lot faster
than doing lookups on a database.

WHAT I WANT TO DO:
- Write a C/C++ program that is constantly running that is dedicated
to doing this data intensive operation.
- This program would read all the data from the dbase into memory upon
load. Then it would take requests from a PHP script to run the
operation on that data and return the results to the PHP script.




此程序已编写很久以前;它被称为MySQL。

MySQL支持HEAP表,与任何其他表不同,它是存储在内存中而不是存储在磁盘上的。有关详细信息,请参阅MySQL手册:

http://dev.mysql.com/doc/mysql/en/me...ge-engine.html


此外,还有一个使用HEAP表,没有

加速任务的可能性很大。减少查询的数量(即,使用一个

复杂的查询而不是一系列简单的查询),如果您的索引尽可能多地帮助,请考虑

,以及或许

考虑数据架构的变化是否有助于

更好的性能...


干杯,

NC



This program has been written a long time ago; it''s called MySQL.
MySQL supports HEAP tables, which, unlike any other tables, are
stored in memory, not on disk. See MySQL Manual for details:

http://dev.mysql.com/doc/mysql/en/me...ge-engine.html

Also, there is a good chance that you task can be sped up without
using HEAP tables. Reduce the number of queries (i.e., use one
complicated query instead of a series of simple queries), think
if your indexing is helping as much as it can, and perhaps
consider if a change in data architecture can contribute to
better performance...

Cheers,
NC


Nimit写道:
我想做什么:
- 写一个C /持续运行的C ++程序专门用于执行此数据密集型操作。
- 此程序将在加载时将dbase中的所有数据读入内存。然后它会从PHP脚本请求对该数据运行
操作并将结果返回给PHP脚本。
WHAT I WANT TO DO:
- Write a C/C++ program that is constantly running that is dedicated
to doing this data intensive operation.
- This program would read all the data from the dbase into memory upon
load. Then it would take requests from a PHP script to run the
operation on that data and return the results to the PHP script.




这里有两个想法应该在Windows上工作,但不能在unix上工作。

但是,它可能会给你一些想法。在你尝试这些之前,

虽然,我会真的仔细检查,甚至可能发布一个问题,

你是否正在进行世界上最复杂的计算
,不能加速。最后一个问过这样一个问题的人

竟然混淆了参考资料......


关于肉:你要求的是写一个服务器(这个

不是唯一可能的视图。例如,您可以使用轮询,或者

您的应用可以准备基于文件的相关数据缓存和你的PHP

可以调用第二个应用程序或直接拿起它 - 你想要的东西

将响应客户端(PHP')的请求。 />

COM技术在这里很有用。最直接的事情是

来创建一个充当服务器的COM对象。或许你可以用你的C / C ++知识来实现​​这个目标。对于那些只懂VB,

的人,你可以使用精彩,免费,而且很难找到微软提供的

VB5CCE来创建一个可以使用的.OCX。您创建的OCX或DLL

将充当您的服务器 - 一旦您学会了如何操作,它就非常容易。然后(因为这个COM对象将在后台活着),

你将需要得到它
http://php.net/com_get_active_object 。注意那个页面上的警告

,因为你想要以完全像你警告的那样的方式使用它。但这是我推荐的选项 - 我认为它比选项2的学习开销更少,而且应该更高效,因为它会使用更少的代码。

将会有更少的代码。


使用COM的第二个路径。创建一个CLI(命令行)php

程序将位于后台。这个PHP程序将带来一个隐藏版本的IE(在开发过程中你最好使用一个

可见版本或者你会疯狂)并继续运行通过

com_message_pump。 IE的这个实例是全局可定位的(因为

你会给它一个唯一的标题)。您的服务器PHP脚本将使用



Here are two ideas that should work on Windows, but not on unix.
However, perhaps it will give you some ideas. Before you try these,
though, I would really double check, maybe even post a question about,
whether you are doing the most complicated computations in the world
that just can''t be speeded up. Last guy who asked a question like this
turned out to have mixed up references...

On to the meat: What you are asking for is to write a server (this
isn''t the only view possible. You could use polling, for example, or
your app could prepare a file based cache of relevant data and your PHP
could call a second app or pick it up directly) - you want something
that will respond to a client (PHP''s) request.

COM technology is useful here. The most straighforward thing to do is
to create a COM object which will act as a server. Probably you can
already do this with your C/C++ knowledge. For those who only know VB,
you can use the wonderful, free, and hard to locate Microsoft provided
VB5CCE to create an .OCX that can be used. The OCX or DLL you create
will act as your server - once you''ve learned how to do it, it''s very
easy. Then (since this COM object will be alive in the background),
you will need to get ahold of it with
http://php.net/com_get_active_object. Mind the warning on that page
since you''re wanting to use this in exactly the fashion that the warn
you about. But this is my recommended option - I think it has less
learning overhead than option 2 and should be more efficient since it
will have less code.

There is a second path using COM. Create a CLI (command line) php
program that will sit in the background. This php program will bring
up a hidden version of IE (during development you''d better use a
visible version or you''ll go nuts) and stay running by means of
com_message_pump. This instance of IE is globally locatable (because
you will give it a unique title). Your server PHP script will use


这篇关于PHP脚本与C / C ++程序通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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