472,805 Members | 859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Return value of function is getting added

Dheeraj Joshi
1,123 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
19 1983
Markus
6,050 Expert 4TB
What is the contents of function.php?
Aug 12 '09 #2
Dheeraj Joshi
1,123 Expert 1GB
It is a wrapper for set of C functions.
Aug 12 '09 #3
Markus
6,050 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
1,123 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
6,050 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
1,123 Expert 1GB
Ok.

Thanks for some info Mark...

Does somebody out there knows a solution for this problem?
Aug 12 '09 #7
Markus
6,050 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
1,123 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
8,658 Expert Mod 8TB
@dheerajjoshim
at least not me......
Aug 13 '09 #10
Dheeraj Joshi
1,123 Expert 1GB
Do you have any insight about problem?
Aug 13 '09 #11
Dormilich
8,658 Expert Mod 8TB
nope, havenít done anything as such yet.
Aug 13 '09 #12
Dheeraj Joshi
1,123 Expert 1GB
Ok....

Hope Somebody knows the solution.
Aug 13 '09 #13
Markus
6,050 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
1,123 Expert 1GB
Which source code?

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

Mark.
Aug 13 '09 #19
Dheeraj Joshi
1,123 Expert 1GB
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
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
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
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
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
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
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
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
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
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()
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.