473,544 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3429

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

Jul 17 '05 #2
"Pat A" <pw*******@hotm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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*******@gmai l.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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
1579
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 data-collecting piece of the code runs in a thread. 1. Open the db, and each thread writes the result immediately. (Sub-question: which is better: cursor object...
1
1267
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 language to support threading: Increasing use of threads lead developers to wish for a better way of dealing with thread-local data. The POSIX...
2
1236
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 variables: A asp context wrapper object
17
1428
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 endProgram As Boolean = False Dim image1 As Image = Image.FromFile("..\Images\gun.bmp")
28
7345
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 "good" in such terms, that this core data structure is changed only by atomic operations, so that the data structure is always consistent regarding...
4
1206
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 monitor data from a source and if the conditions are TRUE, it would post a message to the top of a message queue. Then alert Child Thread 2 that...
7
1119
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. Many thanks Jon import threading import sys
2
1901
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":} cpu.CpuMonitor(debug,stats_d).start() db.UpdateDatabase(debug,stats_d).start() And CpuMonitor looks like this:
5
2514
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 queries a database for various attributes. from the debug statements the item names are being retrieved correctly, but the attributes returned are...
0
7437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7373
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7389
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7717
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5928
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3427
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.