473,626 Members | 3,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mantain a variable through several scripts like global.asa variables in asp

Hi,

I have to port from asp a script that adds an ip to a list in plain
text or an array. I need not using a database or filesystem, it has to
be stored in memory in order that giving us best performance (it should
be accessed continuously).

I've tried defining $_ENV vars, using apache_setenv(. .), creating a
class with a static var... but nothing results.

In asp the script writes an reads an Application variable defined in
global.asa... is it impossible to port? isn't it a very big error of
php?

thanks

Dec 27 '05 #1
12 1827
Zeppelin wrote:
Hi,

I have to port from asp a script that adds an ip to a list in plain
text or an array. I need not using a database or filesystem, it has to
be stored in memory in order that giving us best performance (it should
be accessed continuously).
Hi,

The easiest way is just including a file at top of your scripts.
Into that file you define some constants or variables.


I've tried defining $_ENV vars, using apache_setenv(. .), creating a
class with a static var... but nothing results.
Don't.
:-)

Just include a file.

In asp the script writes an reads an Application variable defined in
global.asa... is it impossible to port? isn't it a very big error of
php?
No, this isn't a big error.

If you worry about performance, don't.
Files that are accessed a lot of time will be placed in cache (memory) if
possible by the OS.
Thus no performancepena lty.

On a sidenote: I don't understand why so many people worry about performance
when they do not have a performanceprob lem.
My guess is that over 90% of all performanceprob lems are databaserelated
(bad queries, no indexing, etc) and not scriptinglangua ge related.

If you absolutely want to use shared memory in PHP, that is possible.
I do n't remember the name of the package, but if you look around I am sure
you will find it.
My advise is however: Just include a file.

Regards,
Erwin Moller

thanks


Dec 27 '05 #2
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:43******** *************** @news.xs4all.nl ...
If you absolutely want to use shared memory in PHP, that is possible.
I do n't remember the name of the package, but if you look around I am
sure
you will find it.


Shared memory operations aka. shmop?
http://www.php.net/manual/en/ref.shmop.php

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
an************* ******@gmail.co m.NOSPAM.invalid
Dec 27 '05 #3
Kimmo Laine wrote:
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:43******** *************** @news.xs4all.nl ...
If you absolutely want to use shared memory in PHP, that is possible.
I do n't remember the name of the package, but if you look around I am
sure
you will find it.


Shared memory operations aka. shmop?
http://www.php.net/manual/en/ref.shmop.php


That is the one. :-)
I couldn't remember its impossible name. :P

Regards,
Erwin Moller

Dec 27 '05 #4
>I have to port from asp a script that adds an ip to a list in plain
text or an array. I need not using a database or filesystem, it has to
be stored in memory in order that giving us best performance (it should
be accessed continuously).
Have you actually MEASURED the performance to prove this?
Often, even program code isn't stored in memory most of the time.

If your web server gets restarted (software crash, someone trips
over power cable, maintenance), your variable goes poof! Is this
acceptable behavior?
I've tried defining $_ENV vars, using apache_setenv(. .), creating a
class with a static var... but nothing results. In asp the script writes an reads an Application variable defined in
global.asa.. . is it impossible to port? isn't it a very big error of
php?


The closest PHP comes to this is one of:
- Sessions (does not apply to unrelated users)
- Files
- A database
- System V shared memory segments (shm_* functions)

Global variables are in general bad programming practice. Making
varibles that are "ultra-global" over all web page accesses by
unrelated users is asking for even more problems. How, for example,
do you prevent several simultaneous page accesses from simultaneously
updating (and screwing up) the variable? There's a reason why
databases have so many features relating to locking, transactions,
and consistent views of the data.

Gordon L. Burditt
Dec 28 '05 #5
Zeppelin wrote:
In asp the script writes an reads an Application variable defined in
global.asa... is it impossible to port? isn't it a very big error of
php?


Not a big error, just a limit imposed by PHP's cross-platform nature.
It's easy enough to have shared variables on Windows. On Unixes it's
rather more difficult.

There is usually more than one way to skin a cat. If you give us some
details on what the code does, we might be able to suggest an
alternative--and perhaps superior--solution.

Dec 28 '05 #6
> Have you actually MEASURED the performance to prove this?
Often, even program code isn't stored in memory most of the time
I have no stadistics about this, but every new version of applicattion,
servers goes 100% and crashes down. So we want be prepared.
If your web server gets restarted (software crash, someone trips
over power cable, maintenance), your variable goes poof! Is this
acceptable behavior?
Nowadays, the variable is lost and no problems registered. Only than
first 60 clients don't have the best service ... but its only a few
mseconds...
The script could be improved saving the variable to bd every 10 minutes
;)

I will try with System V shared memory segments (shm_* functions) .
Global variables are in general bad programming practice. Making
varibles that are "ultra-global" over all web page accesses by
unrelated users is asking for even more problems. How, for example,
do you prevent several simultaneous page accesses from simultaneously
updating (and screwing up) the variable? There's a reason why
databases have so many features relating to locking, transactions,
and consistent views of the data.


The problem is that this script is not a part of a CMS or simmilar
application... it is the minnimun piece of a big system. It has a very
clear mission and does nothing more.

Dec 28 '05 #7
As I respond later, we haver to worry about performance: we expect to
have about 10 millions of connections in a very few days... lots of
them concurrent.

Each day it is not the situation, but we are going to release a new
version and we know there will be lots of new users. Last time we
released, server crashed down serveral times... Nowadays, machine is
better, but users number has grown up no proportionaly.

The variable is changing everytime, I can't include a file because
variable is shared. The change that makes a user is needed by next
user.

I will try with shard memory as you say.

In any case, thank you ;).

Dec 28 '05 #8
> There is usually more than one way to skin a cat. If you give us some
details on what the code does, we might be able to suggest an
alternative--and perhaps superior--solution.


Ok, really simple:

detect user's real ip
load users ip table (this is my shared variable)
send 60 equispaced items of the table to user (as body of http
response)
rotate ip's, loosing first item and adding the detected ip at the end
end

I suppose it would be more effective if we used a dedicated mini-server
for this simple script or write it in another language (bash?) and
redirect the requests of this service with apache to it. But I thought
it would be simplier using php.

Dec 28 '05 #9
Zeppelin wrote:
Have you actually MEASURED the performance to prove this?
Often, even program code isn't stored in memory most of the time

I have no stadistics about this, but every new version of applicattion,
servers goes 100% and crashes down. So we want be prepared.


So, instead of determining where the slowdown is, you're grasping at
straws? Spending a lot of time trying to code something which could
crash the server and may or may not resolve the problem, instead of
determining the cause of the problem?

I would think offloading some of the work would be more efficient. For
instance, if you're supplying a download, have another server actually
perform the download. Using a database? Put the database on a
different server. And so on.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 28 '05 #10

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

Similar topics

4
3679
by: Kasper K | last post by:
Hi, I'm using PHP with apache. From what I understand, global variables are only global to one php script (i.e. the file and all the files it includes), but they are not persisted between HTTP calls. Can you have truly global variables that persist between scripts?
83
6478
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in C. It can cause very ugly errors,like this: epsilon=0 S=0 while epsilon<10: S=S+epsilon
5
5315
by: Richard A. DeVenezia | last post by:
Dear Experts: Suppose I have global variables: x1, x2, x3 and I have a function that needs to assign a value to a new global variable x4 something like function foo () { count = 0;
5
3288
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used to be in that single file, that worked OK. But when I divdie that file into several ones, I have many "invalid use of undefined type" errors. The four files are main.c, main.h, readLP.h, and readLP.c. In readLP.h
6
1471
by: Maarten | last post by:
Here is a nice problem. I have two scripts, one calling the other with via an include. The script that is included contains a variable, a function and a call to that function. The variable needs to be accessible to the function, so I declare it having a global scope. Then I execute the function, which should echo the value of the variable. Contrary to what I expected, the variable isn't there. The code of the 2 programs is: script1.php
148
5489
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
1
25659
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
34
5585
by: Kurda Yon | last post by:
Hi, As you have recommended I did not use the session_register(). In one file I have executed such line: $_session = 2.0; Then, in another file, I have executed the following line: $ex = 3.0. And than I have noticed that the previous assignment is seen
112
5421
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
0
8265
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7193
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2625
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.