473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

PHP and Threading - is it possible?

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

Jul 17 '05 #1
14 1761
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
Jul 17 '05 #2
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.
Jul 17 '05 #3
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

Jul 17 '05 #4
Can you show me an example online of how you can, entirely in PHP,
ensure a "lock file" mechanism that will work in the PHP stateless
environment? That is, you lock.. something.

What do you lock? How do you lock it? I have MySQL "LOCK TABLE"
routines set up, but that doesn't prohibit the following fundamental
problem from occurring:

1) User A goes to associate two sets of database records together
2) User B, at the exact same time, happens to be DELETING the second
set of database records

I'm sorry but locking files and/or db in this case is simply not
practical. You would have to somehow lock the entire object
application instance STATE, across the board, to ensure that User A, or
user User B, depending on the connection pool, will get their action
logically accomplished.

Phil

Jul 17 '05 #5

"comp.lang.php" <ph**************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Can you show me an example online of how you can, entirely in PHP,
ensure a "lock file" mechanism that will work in the PHP stateless
environment? That is, you lock.. something.

What do you lock? How do you lock it? I have MySQL "LOCK TABLE"
routines set up, but that doesn't prohibit the following fundamental
problem from occurring:

1) User A goes to associate two sets of database records together
2) User B, at the exact same time, happens to be DELETING the second
set of database records

I'm sorry but locking files and/or db in this case is simply not
practical.
Yes it is. I have been programming that way for 25+ years.
You would have to somehow lock the entire object
application instance STATE, across the board, to ensure that User A, or
user User B, depending on the connection pool, will get their action
logically accomplished.


I don't know where you get your ideas from, but you do not lock an entire
APPLICATION or the STATE of an application, you lock the files you are about
to update/delete. If two users try to lock the same file at the same time
then it's a case of "first come, first served". The second lock will not be
allowed to continue until the first lock is released.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #6
The newsgroup comp.lang.php itself wrote:
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.


http://www.vl-srm.net/

Regards,
Matthias
Jul 17 '05 #7
Thanx, however, this requires PHP 4.3.7+, and I'm working with PHP
4.3.2 and 4.1.2 (this will be in multiple environments).

Sorry
Phil

Jul 17 '05 #8
Does your 25+ years of programming and "first come first served"
solution involve connection pools and NOT flat files as you are
implying.?? I'm not working with flat files in this case but with the
need for a persistent state that is, for example, illustrated within
Java's Thread-based objects within a connection pool. Can you using
PHP 4+ and MySQL 4 utilize unique concurrent connections to the very
same MySQL database instance?

Phil

Jul 17 '05 #9
"comp.lang.php" <ph**************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Does your 25+ years of programming and "first come first served"
solution involve connection pools and NOT flat files as you are
implying.?? I'm not working with flat files in this case but with the
need for a persistent state that is, for example, illustrated within
Java's Thread-based objects within a connection pool. Can you using
PHP 4+ and MySQL 4 utilize unique concurrent connections to the very
same MySQL database instance?


Actually, even flat files are pretty hard to lock across multiple requests
in PHP :-p

I don't know a whole lot about Java, but the method you described doesn't
sound right to me. You don't use a synchronization object in the application
layer to protect a resource in the database layer. I mean, what if there're
more than one app server accessing the database? The locking mechanism
should be implemented in the database itself. To grant access to a user,
just set a ownership column in the table to the user id. To release a
resource, set the column to null.
Jul 17 '05 #10
With none of the languages I have ever worked with, including PHP, has the
idea of multiple clients sharing the same database connection ever arisen.
Each request has its own connection, and when that request is complete the
connection is closed. The exception to this is persistent connections, but
even then one connection can only service requests from one client.

What you are describing may be relevant in Java, but it is irrelevant in
PHP.

--
Tony Marston

http://www.tonymarston.net
"comp.lang.php" <ph**************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Does your 25+ years of programming and "first come first served"
solution involve connection pools and NOT flat files as you are
implying.?? I'm not working with flat files in this case but with the
need for a persistent state that is, for example, illustrated within
Java's Thread-based objects within a connection pool. Can you using
PHP 4+ and MySQL 4 utilize unique concurrent connections to the very
same MySQL database instance?

Phil

Jul 17 '05 #11
comp.lang.php wrote:
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.


When working with PHP you should think it's way instead of forcing it to do
things it was not intended to. PHP is a good language for Web development
because it's philosophy closely mirrors the way the Web works; most other
languages have to adapt themselves somehow.

HTTP is a stateless protocol: when you load a HTTP response/page, which
gives you a state that was on the server the moment it was sent from there,
you have no idea what happens on the server -- the state there might
completely change and you and your browser will have no clue about it.

Consider a simple Web page (ie. no programming involved), and this scenario:
you open the page, say mypage.html, from my Web server, and while you're
reading it I delete it on the server. Although it exists no more (ie. its
state has changed), you still can see it until you try to load it again (or
even then for some time, depending on your browser's caching settings).

PHP is basically, as its new name nicely sums, a hypertext preprocessor:
when you request a HTTP address which calls a PHP script, it does nothing
else but preparing the output which will be sent by the server to your
browser. Historically, PHP is a simple procedural language, and each time
you call a script it executes anew, parsing and interpreting each
instruction one by one. There is no way -- and originally there was no
need -- to keep variables and its states in permanent memory, since most of
the time all persistent data was in databases or files (PHP has an excellent
mechanism to dynamically load and execute other PHP files, which are then
executed as if a part of the original script).

Through its evolution, PHP has gained various advanced features such as OOP,
but its essence -- it being the typical scripting language -- has remained
the same. With PHP there is no compile-time, everything is parsed and
evaluated only on run-time; and as it has no strong types, it is one of the
most dynamic languages in use: you can dynamicaly include libraries, assign
values or even load interpreter modules, or even such "perversions" like
variable variables, where you can decide which variable will be accessed (or
function/method called) by constructing its name dynamically.

Anyway, one should have in mind the specifics of the language working with,
regardless of which language it is. Basically, everything is possible with
every language: I have seen procedural applications written in Java (one
class, one main() method), as well as PHP OO bloatware with a hundred lines
of code and a separate template meta-language just for a simple Web site
(even without database!). So, when working in PHP you should think in PHP,
and ask more experienced programmers how to solve various issues (which
often turn out to be no issues at all).

Berislav
Jul 17 '05 #12
Thanx for a very comprehensive breakdown of the scope of PHP vs the
scope of having to work with persistent states.

What I am looking into would obviously have to be outside of PHP for
the solution, concentrating more with MySQL with table locking and
prioritizing transactional SQL statements. Might not be the best route
but I think that's all I have to work with at the moment.

Thanx again!

Phil

Jul 17 '05 #13
Perhaps if you rephrase your Original Post explaining exactly what you
are trying to accomplish, somebody might be able to explain how to
accomplish it in PHP.

All of the "issues" you have raised so far about collisions in your
database inserts,updates,and deletes should be resolvable through the
use of transactions.

If you have a specific situation in mind that you think cannot be
resolved, it would be helpful if you could provide an outline of the
steps you are stuck on and maybe then someone will think of a way to
successfully complete those steps in PHP.

Jul 17 '05 #14
comp.lang.php wrote:
Thanx for a very comprehensive breakdown of the scope of PHP vs the
scope of having to work with persistent states.

What I am looking into would obviously have to be outside of PHP for
the solution, concentrating more with MySQL with table locking and
prioritizing transactional SQL statements. Might not be the best
route but I think that's all I have to work with at the moment.


A brief, but strong suggestion: use ADOdb for database access:
http://adodb.sourceforge.net/

Berislav
Jul 17 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jorge Godoy | last post by:
Hi! I must have been searching in the wrong places or with the wrong keywords but I couldn't find out how to implement something such as what is done by the threading module on Windows (95, 98...
12
by: Jerry Sievers | last post by:
Greetings Pythonists; I have limited experience with threaded apps and plenty with old style forked heavyweight multi-processing apps. Using Python 2.3.3 on a Redhat 7.x machine. Wondering...
8
by: Yatharth | last post by:
Hi, I m new to threading and i have successfully runed threading but i could display value on my web page ,but its working in code behind when i see it through debugger,plzzzzzzz help me here...
5
by: microsoft | last post by:
Just researching threading and I'm sure we need to do more review of available resources BUT I'm wondering if what we're looking for is actually possible. If it is we can keep reading. I know...
0
by: juxstapose | last post by:
Hello, I have been develop a blocking socket application with threading. The main thread handles connections and inserts them into python's protected queue as jobs for the thread pool to handle....
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
0
by: smimon | last post by:
Hi I'm trying to run a DTS package from a ASP.NET web page using System.Diagnostics.Process. This DTS takes up to 10 minutes to complete, during which, output is generated which i would like to...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.