PHP和线程 - 它可能吗? [英] PHP and Threading - is it possible?

查看:59
本文介绍了PHP和线程 - 它可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里和其他论坛上听过很多不同的评论

关于PHP和线程的概念。来自Java

背景我理解线程如何有利于防止冲突,所有这些都是为了避免竞争条件而小心编写的。虽然在多用户环境中使用了一个web

应用程序。


然而,仅在PHP中有相同技术的例子吗? >
可能吗?我面临着必须处理我构建的Web应用程序中潜在的

冲突问题,因为一个用户可以删除

完全相同的数据/文件/对象另一个用户同时

创建,但是,要求是应用必须是

多用户友好。


这怎么能用PHP完成,如果有的话,否则,你有什么建议开源和非许可的



Phil

解决方案

comp.lang.php写道:

我在这里和其他论坛上听过很多不同的评论
关于PHP和线程的概念。来自Java
背景我理解线程如何有利于防止冲突,所有这些都是在仔细编写的同时避免竞争条件。而在多用户环境中使用web
应用程序。

然而,仅在PHP中有哪些例子可以使用相同的技术吗?我面临着必须处理我构建的Web应用程序中潜在的冲突问题,因为一个用户可以删除另一个用户同时创建的完全相同的数据/文件/对象,但是,要求应用程序必须是多用户友好的。




PHP是一种无状态语言,这意味着对象仅存在于

请求处理。换句话说,在每个请求中脚本再次运行,

并且必须从头开始重建整个环境(对象,它们的状态等)

。实际上,这意味着在每次调用时都会访问一组不同的
对象,唯一的常见数据是存储在数据库中或者其他形式的持久性。


Berislav


comp.lang.php写道:

我''在这里以及关于PHP和线程概念的其他论坛上,我听到过各种各样的评论。来自Java
背景我理解线程如何有利于防止冲突,所有这些都是在仔细编写的同时避免竞争条件。而在多用户环境中使用web
应用程序。

然而,仅在PHP中有哪些例子可以使用相同的技术吗?我面临着必须处理我构建的Web应用程序中潜在的冲突问题,因为一个用户可以删除另一个用户同时创建的完全相同的数据/文件/对象,但是,要求应用程序必须是多用户友好的。



人们多年来一直在解决这个问题而不使用线程。你正在尝试使用PHP进行编程,就好像它是Java一样 - 但事实并非如此。如果您的目标是

只是为了确保对文件的独占访问,那么建立一个机制来实现它 - 比如锁定文件。


HTH

C.


那是一个主要的根本问题。因为如果你说的是

为真,那么为了设置一个持久的环境来处理潜在的碰撞,你必须要有相当于PHP的等价物。 >
BEA / WebLogic作为与

应用程序一起运行的应用程序服务器,以确保有序的持久状态环境,如果

我记得那里什么都没有未经许可的开源

PHP-dom如果错了,请指出我正确的方向。


Phil


I''ve heard numerous and varied commentaries here and on other fora
regarding PHP and the concept of threads. Coming from a Java
background I understand how threads benefit to prevent collisions, all
the while carefully written to avoid "race conditions" while a web
application is being utilized in a multi-user environment.

However, are there examples in PHP alone where this same technology is
possible? I am faced with having to deal with the issue of potential
collisions within a web application I built since one user could delete
the exact same data/files/objects another user is simultaneously
creating, however, requirements are that the app must be
multi-user-friendly.

How can this be done in PHP, if at all, otherwise, what do you
recommend that is open-source and non-licensed?

Phil

解决方案

comp.lang.php wrote:

I''ve heard numerous and varied commentaries here and on other fora
regarding PHP and the concept of threads. Coming from a Java
background I understand how threads benefit to prevent collisions, all
the while carefully written to avoid "race conditions" while a web
application is being utilized in a multi-user environment.

However, are there examples in PHP alone where this same technology is
possible? I am faced with having to deal with the issue of potential
collisions within a web application I built since one user could
delete the exact same data/files/objects another user is
simultaneously creating, however, requirements are that the app must
be multi-user-friendly.



PHP is a stateless language, meaning that the objects exist only during the
request processing. In other words, in each request the script is run again,
and the entire environment (objects, their states etc) have to be rebuilt
from scratch. In practice, this means that on each call a different set of
objects are accessed, and the only common data is that stored in database or
some other form of persistence.

Berislav


comp.lang.php wrote:

I''ve heard numerous and varied commentaries here and on other fora
regarding PHP and the concept of threads. Coming from a Java
background I understand how threads benefit to prevent collisions, all
the while carefully written to avoid "race conditions" while a web
application is being utilized in a multi-user environment.

However, are there examples in PHP alone where this same technology is
possible? I am faced with having to deal with the issue of potential
collisions within a web application I built since one user could delete
the exact same data/files/objects another user is simultaneously
creating, however, requirements are that the app must be
multi-user-friendly.


People have been solving this for years without using threads. You''re trying
to program in PHP as if it were Java - it''s not. If your objective is
merely to assure exclusive access to files then build a mechanism to
implement it - like lock files.

HTH

C.


That is a major fundamental problem then. Because if what you say is
true, then in order to set up a persistent environment to handle
potential collisions, one would have to have the PHP equivalent of
BEA/WebLogic as an application server running alongside your
application to ensure an ordered persistent-state environment, which if
I remember there is nothing out there unlicensed open-source in
PHP-dom, if wrong, point me in the right direction, please.

Phil


这篇关于PHP和线程 - 它可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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