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

PHP Threading and global variables

Are global variables thread safe? We are seeing competing threads
modifying global variables on calls to the same page. We are running in
ISAPI mode. Are globals protected internally inside of the PHP runtime
with a semaphore or some other mechanism?

Jul 17 '05 #1
5 3415

By the way, we are only seeing this on a multi-processor machine.

Jul 17 '05 #2
"Pat A" <pw*******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Are global variables thread safe? We are seeing competing threads
modifying global variables on calls to the same page. We are running in
ISAPI mode. Are globals protected internally inside of the PHP runtime
with a semaphore or some other mechanism?


Yes. They managed, along with all internal data, by TSRM, the PHP
thread-safe resource manager. Based on the id of current thread, a block of
memory is obtained/allocated by TSRM. The thread data registry itself is
protected by a mutex.

The behavior you described is rather odd. As far as I know, there is no
thread-unsafe version of the PHP engine for Windows.

Can you show us some code sample?
Jul 17 '05 #3
We're seeing the problem in the free FPDF library. We have a php page
that instantiates the FPDF class multiple times in a loop. The
instances of FPDF seem to be stepping on each other.

Jul 17 '05 #4

"Pat A" <pw*******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
We're seeing the problem in the free FPDF library. We have a php page
that instantiates the FPDF class multiple times in a loop. The
instances of FPDF seem to be stepping on each other.


Unfortunately, not all PHP extension are threadsafe. You might want to
contact the people who wrote FPDF.
Jul 17 '05 #5
Chung Leong wrote:
"Pat A" <pw*******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
We're seeing the problem in the free FPDF library. We have a php page
that instantiates the FPDF class multiple times in a loop. The
instances of FPDF seem to be stepping on each other.

Unfortunately, not all PHP extension are threadsafe. You might want to
contact the people who wrote FPDF.

Don't rely upon PHP being thread safe, the problem doesn't lie
neccesarily with PHP, its the libraries PHP employs that may - read are
not - thread safe. Assume that any PHP program is running in a thread
unsafe environment - better safe than sory <g>
Jul 17 '05 #6

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

Similar topics

4
by: Antal Rutz | last post by:
Hi, All! I'm new to threading. I have some design questions: Task: I collect data and store them in an RDBMS (mysql or pgsql) The question is how to do that with threading? The...
1
by: Steven T. Hatton | last post by:
I pinned this to my desktop a while back so I'd remember to look at it: http://people.redhat.com/drepper/tls.pdf I just started reading it and realized that there may be a reason to extend the...
2
by: Peter Row | last post by:
Hi, I have a VB6 webclass app that was ported to VB.NET. However due to multithreading now being used the global variables used have come to haunt me. Problem: I have a handful of global...
17
by: One Handed Man \( OHM - Terry Burns \) | last post by:
Assumes a Form with a Panel on it., Does the Mutex have to be within the address of a thread start address ? Cheers - OHM '----------- *************** ---------------- Private...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
4
by: CirclesTraveled | last post by:
Hello Everyone, I have to write a program that uses multiple threads. Simply, this is what I want to do. 1) The parent thread will spawn at least two child threads. 2) Child Thread 1 will...
7
by: jrpfinch | last post by:
I'm just getting started on threading and was wondering why the following code does not work (i know globals is bad style - I'll eliminate them eventually). All I get is a blank cursor flashing. ...
2
by: mattbennett | last post by:
Hi, I'm new to python, and having problems instantiating classes. My main method has a couple of lines like this: debug = False stats_d = {"cpu":,"foo":,"bar":,"baz":} ...
5
by: skunkwerk | last post by:
i'm getting the wrong output for the 'title' attributes for this data. the queue holds a data structure (item name, position, and list to store results in). each thread takes in an item name and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.