473,396 Members | 1,743 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,396 software developers and data experts.

PHP Multi-threading

As multi-threading is not built in PHP I've been using a hack letting
the Apache server handle the multi-threading issues, but I'm really
curious of other approaches to this issue.

If anyone has any ideas I'd be more than glad to hear them up and
discuss them.
Mar 31 '08 #1
5 3508
George Maicovschi schreef:
As multi-threading is not built in PHP I've been using a hack letting
the Apache server handle the multi-threading issues, but I'm really
curious of other approaches to this issue.

If anyone has any ideas I'd be more than glad to hear them up and
discuss them.
Hi George,

I take it you are working on Apache2?
Well, as far as I understood PHP isn't threadsafe (yet).
Not to mention all the additional packages (for DB access eg).

I wouldn't go for such an approach in any productionenvironment.

The following articles might shed some light on the issues:

http://certcities.com/editorial/colu...itorialsID=102
http://neosmart.net/blog/2008/dont-b...read-safe-yet/

Unless you have some compelling reason to use a threaded webserver, I
think, for now, the best option is fastcgi, if performance is an issue.

If you are just experimenting, consider this message not sent. ;-)

Regards,
Erwin Moller
Mar 31 '08 #2
Hey Erwin,

It's just an experiment of mine, nothing production-related... YET :-)

The thing goes like this. I have a script that's supposed to do an
action on lets say 100 different hosts in the same time. So I need
multi-threading ar a way to emulate it. My approach was this:

$threads=array();
$responses=array();
foreach ($hosts as $host)
$threads=fopen('http://domain.with.the.script/path/to/script/
script.php?op=action&host={$host}','r');

foreach ($threads as $thread_id=>$thread)
if ($thread)
{
$responses[$thread_id]=''
while (!feof($thread))
$response[$thread_id].=fgets($thread);
fclose($thread);
}

So now the threading part is emulated through Apache, making
concurrent requests to the script.php that contains the actions to be
undertaken and specifying the host that I want to be the target of the
actions.

Basically that's my approach to multi-threading emulation in PHP.

So...any suggestions/ideas/anything? :-)

I am really curious about other approaches because this multi-
threading thing in PHP seems rather disturbing because of it's
absence. :-)

Cheers,
George Maicovschi.
Mar 31 '08 #3
George Maicovschi wrote:
Hey Erwin,

It's just an experiment of mine, nothing production-related... YET :-)

The thing goes like this. I have a script that's supposed to do an
action on lets say 100 different hosts in the same time. So I need
multi-threading ar a way to emulate it. My approach was this:

$threads=array();
$responses=array();
foreach ($hosts as $host)
$threads=fopen('http://domain.with.the.script/path/to/script/
script.php?op=action&host={$host}','r');

foreach ($threads as $thread_id=>$thread)
if ($thread)
{
$responses[$thread_id]=''
while (!feof($thread))
$response[$thread_id].=fgets($thread);
fclose($thread);
}

So now the threading part is emulated through Apache, making
concurrent requests to the script.php that contains the actions to be
undertaken and specifying the host that I want to be the target of the
actions.

Basically that's my approach to multi-threading emulation in PHP.

So...any suggestions/ideas/anything? :-)

I am really curious about other approaches because this multi-
threading thing in PHP seems rather disturbing because of it's
absence. :-)

Cheers,
George Maicovschi.
Where are you creating new threads?

I agree with Erwin - if you need to use threads, PHP isn't a good way to
go. If you really need this and it's has to be in PHP, I'd look at
spawning multiple processes off and do the work in batch mode, perhaps
saving the results in a database.

But personally I'd be looking at another language such as Java or C/C++
which has good thread support.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 31 '08 #4
On Mar 31, 5:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
George Maicovschi wrote:
Hey Erwin,
It's just an experiment of mine, nothing production-related... YET :-)
The thing goes like this. I have a script that's supposed to do an
action on lets say 100 different hosts in the same time. So I need
multi-threading ar a way to emulate it. My approach was this:
$threads=array();
$responses=array();
foreach ($hosts as $host)
$threads=fopen('http://domain.with.the.script/path/to/script/
script.php?op=action&host={$host}','r');
foreach ($threads as $thread_id=>$thread)
if ($thread)
{
$responses[$thread_id]=''
while (!feof($thread))
$response[$thread_id].=fgets($thread);
fclose($thread);
}
So now the threading part is emulated through Apache, making
concurrent requests to the script.php that contains the actions to be
undertaken and specifying the host that I want to be the target of the
actions.
Basically that's my approach to multi-threading emulation in PHP.
So...any suggestions/ideas/anything? :-)
I am really curious about other approaches because this multi-
threading thing in PHP seems rather disturbing because of it's
absence. :-)
Cheers,
George Maicovschi.

Where are you creating new threads?

I agree with Erwin - if you need to use threads, PHP isn't a good way to
go. If you really need this and it's has to be in PHP, I'd look at
spawning multiple processes off and do the work in batch mode, perhaps
saving the results in a database.

But personally I'd be looking at another language such as Java or C/C++
which has good thread support.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Yeah, I would go the C way myself, but it has to be PHP...
Mar 31 '08 #5
George Maicovschi wrote:
On Mar 31, 5:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>George Maicovschi wrote:
>>Hey Erwin,
It's just an experiment of mine, nothing production-related... YET :-)
The thing goes like this. I have a script that's supposed to do an
action on lets say 100 different hosts in the same time. So I need
multi-threading ar a way to emulate it. My approach was this:
$threads=array();
$responses=array();
foreach ($hosts as $host)
$threads=fopen('http://domain.with.the.script/path/to/script/
script.php?op=action&host={$host}','r');
foreach ($threads as $thread_id=>$thread)
if ($thread)
{
$responses[$thread_id]=''
while (!feof($thread))
$response[$thread_id].=fgets($thread);
fclose($thread);
}
So now the threading part is emulated through Apache, making
concurrent requests to the script.php that contains the actions to be
undertaken and specifying the host that I want to be the target of the
actions.
Basically that's my approach to multi-threading emulation in PHP.
So...any suggestions/ideas/anything? :-)
I am really curious about other approaches because this multi-
threading thing in PHP seems rather disturbing because of it's
absence. :-)
Cheers,
George Maicovschi.
Where are you creating new threads?

I agree with Erwin - if you need to use threads, PHP isn't a good way to
go. If you really need this and it's has to be in PHP, I'd look at
spawning multiple processes off and do the work in batch mode, perhaps
saving the results in a database.

But personally I'd be looking at another language such as Java or C/C++
which has good thread support.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Yeah, I would go the C way myself, but it has to be PHP...
That's a shame because you're trying to use a hammer when you need a
screwdriver.

There really is no *good* way to do it in PHP. About the only way
you're going to be able to do it is like I suggested above - spawn off
multiple processes to do the work and collect the results in a database
or similar.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 31 '08 #6

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

Similar topics

4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.