473,486 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Return value of function is getting added

Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Hi...

I have a php script which has a function call and function returns a value.

But when i open it in browser and refresh the page the return value will get added to the old value.

Code is:
Expand|Select|Wrap|Line Numbers
  1. <? php
  2.  
  3. include("function.php");
  4.  
  5. $res=0;
  6.  
  7. $res=function::fn_call()
  8.  
  9. echo $res;
  10.  
  11. ?>
  12.  
When i run it in Terminal i will always get the desired value, but when i run it on browser. first time it displays currect value and on page refresh it adds the return value to old returned value.

i.e if return value echoed for 1st time is 4000 after page refresh i displays 8000, after next refresh 12000 and so on.

Script runs perfectly in terminal.
I am hosting pages on nginx and server log do not say anything as error.

Any idea why it behaves strangly?

Regards
Dheeraj
Aug 12 '09 #1
19 2015
Markus
6,050 Recognized Expert Expert
What is the contents of function.php?
Aug 12 '09 #2
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
It is a wrapper for set of C functions.
Aug 12 '09 #3
Markus
6,050 Recognized Expert Expert
As a guess (because you failed to answer my previously question sufficiently), I'd say the problem is this: the SAPI that a web server uses is continuous, as opposed to the SAPI that CLI uses, which is request-based. Therefore, it's how you're implementing those C wrappers that is the problem, but I cannot be any more specific because I am in no way shape or form an expert on Zend extensions (I only know a little).

I recommend you read the book 'Extending and Embedding PHP' - google will show you where to get it (although it is slightly outdated).

Mark.
Aug 12 '09 #4
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
I am using SWIG to Wrap my C functions.

And one more thing what i dont understand is why it gives desired output in the terminal not in browser?
Aug 12 '09 #5
Markus
6,050 Recognized Expert Expert
@dheerajjoshim
Like I said, from what I can remember (I will have to read it again), a web-server uses a continuous SAPI, that is, once the server is started, any memory it uses is not reclaimed until the server is stopped/restarted, unless the memory is explicitly freed by the server/extension. So, if a C extension uses some memory when the server cycle starts and doesn't free it at the end of a request (I will explain about this more when I have re-read the book), the memory is retained.

The CLI (terminal/command-line) SAPI is started and stopped with each request - therefore, Zend frees up it's memory when the cycle ends - when the script you're executing ends.

But don't quote me on any of that.

Mark.

P.S. It's hard to explain something when you don't fully remember / understand what you read - so, hopefully, I'll make more sense when I have read it again.
Aug 12 '09 #6
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Ok.

Thanks for some info Mark...

Does somebody out there knows a solution for this problem?
Aug 12 '09 #7
Markus
6,050 Recognized Expert Expert
@dheerajjoshim
... if we saw the source-code, then we might be able to help; we're not psychics.
Aug 12 '09 #8
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Definitely not psychics.....

All i wanted to know is did somebody got a problem like this in past?? if yes, how they tackled it..
Aug 13 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
@dheerajjoshim
at least not me......
Aug 13 '09 #10
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Do you have any insight about problem?
Aug 13 '09 #11
Dormilich
8,658 Recognized Expert Moderator Expert
nope, haven’t done anything as such yet.
Aug 13 '09 #12
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Ok....

Hope Somebody knows the solution.
Aug 13 '09 #13
Markus
6,050 Recognized Expert Expert
@dheerajjoshim
Look, what I'm telling you is: if we do not see the source-code, the chances of us being able to help you are incredibly slim.
Aug 13 '09 #14
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Which source code?

C or PHP?
Aug 13 '09 #15
Markus
6,050 Recognized Expert Expert
@dheerajjoshim
Both - and use [code] tags please.
Aug 13 '09 #16
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Sorry mark, cant give c code.. It belong to somebody else.... I dont have permission to upload it in internet.
Aug 13 '09 #17
gopan
41 New Member
@dheerajjoshim
Then how will we understand your problem...

Try to make a mock code that generates the same problem and upload it... even that can help us to solve your problem.
Aug 13 '09 #18
Markus
6,050 Recognized Expert Expert
@dheerajjoshim
Then we cannot help you.

Mark.
Aug 13 '09 #19
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
I got a work around to deal with this problem.

I am getting correct results now.
Aug 14 '09 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2610
by: Neil Schemenauer | last post by:
python-dev@python.org.] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is...
13
2135
by: Sara | last post by:
I have a query that pulls data for the month, using the Month End Date from a form (user enters) as criteria. It works. I want to use the same query to pull "month to date" data, on a weekly...
16
7927
by: Esteban404 | last post by:
I have a Winform news kiosk app which connects to a SQL database. When the main form is running, it reaches a threshold time or number of sequential operations and then loads another instance with...
1
2842
by: WLF | last post by:
I have the following function (C# behind aspx page): private void ButtonNewSupplier_Click(object sender, System.EventArgs e) { Response.Write("<script...
5
3956
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
20
6925
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
2
1898
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
127
4747
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
49
2669
by: Davy | last post by:
Hi all, I am writing a function, which return the pointer of the int. But it seems to be wrong. Any suggestion? int * get_p_t(int t) { return &t; } int main()
0
6964
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...
0
7175
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...
0
5434
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,...
1
4865
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...
0
4559
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...
0
3070
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.