Jump to content


Photo

functions


  • Please log in to reply
7 replies to this topic

#1 GHW_Chronic

GHW_Chronic
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 July 2006 - 07:05 PM

If I do this:

function OMFG($id)
{
  return $id + 1;
}


and I don't use the OMFG function, will the php script still load the function?

See, I have 2 very large functions that I don't want to be loaded if the page is not using them because it would delay the page on load.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 July 2006 - 07:07 PM

PHP will load the function, but it wont run the function untill it you tell it to. Also the two functions shouldn't cause any problems with the page load times.

#3 GHW_Chronic

GHW_Chronic
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 July 2006 - 07:11 PM

the functions are 1000 lines total together. So PHP will read none of these lines unless one of the functions is used?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 07:14 PM

Put the functions into separate files and use the include function when you write scripts that call them. If you don't include them, then your scripts won't have the overhead.

Ken

#5 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 05 July 2006 - 07:32 PM

Surely you can break these functions up into smaller single action functions?  Any single function that is 1000 lines has gone beyond the scope of a function.  It sounds like you should be creating a class with methods in this case.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#6 GHW_Chronic

GHW_Chronic
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 July 2006 - 07:40 PM

The functions are for 2 things. 1: pawn highlighting (smaller function) 2: amxmod to amxmodx auto-converter (which unless you know what pawn, amx, and amxx are, you don't know what I'm talking about). And the length of these functions is minimal.

And I'm just going to have to seperate these functions from the other functions in the include file. I didn't want to have to do this, but I guess I will if PHP is going to want to read these functions everytime the page loads.

#7 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 05 July 2006 - 08:21 PM

If there is no way to break them up then why not just add an if case at the top of the page you want to use them on, but only sometimes, and not include the file on condition A.

So,
if (!isset($_POST['user_request']))
{
// just diplay the page with a form or something
} else {
include('a_really_big_function.php');
include('another_rbf.php');
// use them now, they were only loaded when needed
// print stuff out for the user
}

Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#8 GHW_Chronic

GHW_Chronic
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 July 2006 - 08:25 PM

again you missed the point. I ALWAYS want to include the first 4 functions in an included file. I only want the last 2 functions if they are used in a page. They are all in the same file. But I will just force myself to seperate the files into amxx_functions.php and amxx2_funcstions.php.

[End Topic]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users