467,878 Members | 1,289 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,878 developers. It's quick & easy.

Return value of function is getting added

Dheeraj Joshi
Expert 1GB
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
  • viewed: 1730
Share:
19 Replies
Markus
Expert 4TB
What is the contents of function.php?
Aug 12 '09 #2
Dheeraj Joshi
Expert 1GB
It is a wrapper for set of C functions.
Aug 12 '09 #3
Markus
Expert 4TB
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
Expert 1GB
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
Expert 4TB
@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
Expert 1GB
Ok.

Thanks for some info Mark...

Does somebody out there knows a solution for this problem?
Aug 12 '09 #7
Markus
Expert 4TB
@dheerajjoshim
... if we saw the source-code, then we might be able to help; we're not psychics.
Aug 12 '09 #8
Dheeraj Joshi
Expert 1GB
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
Expert Mod 8TB
@dheerajjoshim
at least not me......
Aug 13 '09 #10
Dheeraj Joshi
Expert 1GB
Do you have any insight about problem?
Aug 13 '09 #11
Dormilich
Expert Mod 8TB
nope, havenít done anything as such yet.
Aug 13 '09 #12
Dheeraj Joshi
Expert 1GB
Ok....

Hope Somebody knows the solution.
Aug 13 '09 #13
Markus
Expert 4TB
@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
Expert 1GB
Which source code?

C or PHP?
Aug 13 '09 #15
Markus
Expert 4TB
@dheerajjoshim
Both - and use [code] tags please.
Aug 13 '09 #16
Dheeraj Joshi
Expert 1GB
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
@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
Expert 4TB
@dheerajjoshim
Then we cannot help you.

Mark.
Aug 13 '09 #19
Dheeraj Joshi
Expert 1GB
I got a work around to deal with this problem.

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

Post your reply

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

Similar topics

2 posts views Thread by Neil Schemenauer | last post: by
16 posts views Thread by Esteban404 | last post: by
5 posts views Thread by siaj | last post: by
2 posts views Thread by mosesdinakaran | last post: by
127 posts views Thread by sanjay.vasudevan | last post: by
49 posts views Thread by Davy | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.