LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2005, 09:29 AM   #1
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Rep: Reputation: 136Reputation: 136
In PHP why does this lead to a server connection crash?


I noticed a strange thing today.

Till I did this, I had absolutely no problems whatsoever,

PHP Code:
function func ($arg)
{
      
$retval $arg;
      return 
$retval;

Now in some cases I do need to return the same argument that was passed by the function, but this is leading to a bizarre crash, where the http://localhost stops responding and acts as though the site is loading, whereas nothing happens.

When I type http://localhost in konqueror, I at least got this error message:
Code:
An error occurred while loading http://localhost

Connection to host localhost is broken.
Connection to host localhost is broken.

By the way I am passing a constant to the function argument. Could this be the problem?

Last edited by vharishankar; 07-09-2005 at 09:30 AM.
 
Old 07-09-2005, 09:43 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
I forgot to mention. The incredible thing is that if I returned like this:
PHP Code:
function func ($arg)
{
     
$newval $arg ' ' ;
     return 
$newval;

It works perfectly. This is bizarre and incredible. Why am I unable to return the argument but able to return the argument with a space appended.

I am unable to return the same value as the argument even by using sprintf to copy like this. This also leads to a server connection crash.

$newval = sprintf ('%s', $val);
 
Old 07-09-2005, 09:52 AM   #3
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
Now the third incredible thing. This works well in a small sample test, but refuses to work in my main application where the exact problem is reproduced.

How incredible is that? I can confirm that I have no problems with any other code in my main application. It's only this one single thing that is causing all the problem.

I'm sorry for posting repeatedly, but I feel that I must explain my strange problem better.

 
Old 07-09-2005, 10:26 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 870

Rep: Reputation: 207Reputation: 207Reputation: 207
Easy man. Any more points coming to you? Collect all points and konquer the problem. What else does the function do?

"retval" is a common handle. Any scoping issues? I notice (from the sample code) that you don't explicitly declare it.

End
 
Old 07-09-2005, 10:28 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,161

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
Maybe a problem with the HTTP headers, they have to be text/html to render
correctly, try add a
PHP Code:
header('Content-type: text/html'); 
Add this before any output, so maybe near the top of script
 
Old 07-09-2005, 10:31 AM   #6
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
Why should this lead to a server connection crash?

And also the variable name does not matter. There is no scoping issues either because it is the value returned that causes the problem, not the variable itself.

Eg. I am able to return
PHP Code:
function func ($val)
{
      
$newval $val ' ';
      return 
$newval;

without any problems. But if I use
PHP Code:
function func ($val)
{
      
$newval $val;
      return 
$val;

It is leading to a server crash. What could be the ********* problem here?

Last edited by vharishankar; 07-09-2005 at 10:33 AM.
 
Old 07-09-2005, 10:35 AM   #7
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
keefaz, thanks for the suggestion, but that does not solve it. This seems truly an amazing, incredible error. I wish I could explain better, but I have done my best and this has really rendered me stunned.

The return value is valid and I even checked it properly using the command line PHP to output the resulting HTML where everything is tip-top perfect. Why the ******* is the HTTP server having a crash problem?

When this line is removed or a small character is appended to the return value, it works perfectly beautifully.
 
Old 07-09-2005, 10:38 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,161

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
Could you post a complete script example with real values ?
This never happened to me, I am curious to see how do
you use your functions
 
Old 07-09-2005, 10:50 AM   #9
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
Actually it is a very big script indeed (or growing big). This is a project I am doing "Link directory" using PHP with HTML templates and so on. There are several files involved and more than 500 - 600 lines of code already.

Shall I email you the code with the files as the attachments? I don't think I'll be able to post them here. You will need all the files including the templates, the includes and the config settings to be correct for it to work on your end.
 
Old 07-09-2005, 10:52 AM   #10
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,161

Rep: Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698Reputation: 698
If you can't reproduce this behaviour in a simple script,
obviously the problem isn't in this function, it's elsewhere
 
Old 07-09-2005, 10:53 AM   #11
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
I have a better idea. I shall upload this to my remote web server and then provide you a URL. Just try testing the program at your end and report the problem.

Then I'll change the code to work properly and then you can try again.

This way, I'll be able to check whether it's just my local server problem or a PHP problem.

If you need any portion of the code, I'll just email it to you tomorrow.

It's now > 9:30 pm here and I think I'm going to bed now.

Thanks for your help!
 
Old 07-09-2005, 11:06 AM   #12
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
I have narrowed down this problem further and this grows more and more bizarre.

It's not a problem with the function returning. That works perfectly.

Actually it is a problem like this:

My urls for my application are defined as constants like this in a file called config.php:
PHP Code:
        define ('ADMIN_PAGE''admin.php');
        
define ('INDEX_PAGE''index.php');
        
define ('LOGIN_PAGE''login.php');
        
define ('REGISTER_PAGE''register.php'); 
Now, get this. If I create my HTML file using these URLs, then the server crashes.

However, if I use it like this with a space after each URL:
PHP Code:
        define ('ADMIN_PAGE''admin.php ');
        
define ('INDEX_PAGE''index.php ');
        
define ('LOGIN_PAGE''login.php ');
        
define ('REGISTER_PAGE''register.php '); 
Then it works perfectly!!!!!!!!!!!!!!

This is amazingly stupid. In fact, MAD!!!!!!!! It worked perfectly this morning with the old code and now, all of a sudden the server starts crashing because of some silly problem like this.

Last edited by vharishankar; 07-09-2005 at 11:07 AM.
 
Old 07-09-2005, 11:14 AM   #13
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
I know the problem.

Really stupid problem in my template handling. This has got to be a big problem for me.

Sorry for misleading, but it really eluded me like hell. Now I got a proper error message in my output and I was able to find the culprit. Don't know why the server crashed all the while though.

Should be a memory leak I figure.
 
Old 07-09-2005, 11:18 AM   #14
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,161
Blog Entries: 4

Original Poster
Rep: Reputation: 136Reputation: 136
Fixed it. Actually the real problem was this.

I wanted to pass the string "index.php" "login.php" etc. to my template file as an absolute string.

However the template handler was designed to parse a file name passed in the string if it existed. So this lead to the problem of "index.php" getting included in "index.php" again and again and again. This led to a memory leak I think.

Now I have checked the condition that unless the passed string contains the text ".html" (that is, it is a template file name, not any file name), then it won't get parsed as a file, but as a pure template string.

I hope this explains everything.

Obviously when I passed the space in front of the string, it led to the fact that the file didn't exist and so it got parsed normally as a string.

And because in HTML, the <A HREF> ignores spaces at the end of a URL string, the app worked fine without any errors.

This led to bizarre results.


Last edited by vharishankar; 07-09-2005 at 11:22 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless Connection leads to Hard Crash shapptastic Linux - Wireless Networking 3 07-01-2005 06:48 AM
Wireless Connection leads to Hard Crash shapptastic Linux - Wireless Networking 0 06-27-2005 03:41 PM
LDAP SERVER Client Connection on SUSE 9.2 - connection error jcarton Linux - Networking 3 03-19-2005 12:40 PM
LDAP SERVER - CLIENT CONNECTION on suse 9.2 - connection error nicolasdiogo SUSE / openSUSE 0 03-01-2005 05:43 AM
Separate Internet connection in network DNS crash !!! Rocco1 Linux - Networking 0 02-24-2005 08:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration