Jump to content
xisto Community
Sign in to follow this  
khalilov

Integrating Functions Into The Server for faster processing

Recommended Posts

I am creating a game and for simplicity i am making every possible query a function, ex instead of

$result=mysql_query("SELECT* FROM tablename WHERE columnname=$variable");if($result=mysql_fetch_array($result))   { commands }	else { commands }

i make a function and it becomes

$x=getinfo($variable)if($x)  { commands }	else {commands}

A lot easier to debug for errors and more eye friendly.
However the way it is going there are going to be many functions, 50~100 functions. All will be stored in a file named functions.php, this file will hit ~1000 lines. So including this file in every page on my web would be annoying since i only need 1 or 2 functions tops (about 50 lines of predefined syntax) and i end up adding 1000 lines and prolonging the execution time of a fairly simple script. I'd be defining functions i wont use at the time.
Dividing functions.php into functions1.php, functions2.php.... and including one/some of them depending on the current script in execution might be a solution but i rather not.

My question is that is there a way i can integrate these functions into the server so that they become like standard predefined functions (like echo ,mysql_fetch_array....)?
That way i can call these functions without including anything or worrying about wasted CPU.

thanks in advance :unsure:

Share this post


Link to post
Share on other sites

i think best option is to add it as a module - in the end it's just as adding it as an include or as you define them, a list of fuction scriptsthe other option would be, getting the servers' source code and add your functions to them before compiling

Share this post


Link to post
Share on other sites

i think best option is to add it as a module - in the end it's just as adding it as an include or as you define them, a list of fuction scriptsthe other option would be, getting the servers' source code and add your functions to them before compiling

Share this post


Link to post
Share on other sites

For the first option:So your saying i have no choice but to include about 1000 line in every file while i only need about 50 of them?I am just wondering how much CPU processing power is consumed when you define functions and don't use them, does the server just ignore function definitions and go back to some of those definitions if they are used? meaning including lets say 10,000 lines of code of defining functions does it have no effect if i don't use any of those functions?As for the second option; modifying servers' source code... can you give more details on that?

Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

You would require your own server to compile your own modified php version with those functions and it's not so easy, but why not just use a cache for your php game, like SmartCache?

http://technologies.whitewhale.net/cache/

There are plenty ways to optimize PHP and make better performence, one of them is caching, of course compiled functions work faster than your own written, but it's not as simple as it sounds, writing a flashcache for an IS is hard to and requires a lot of expierence.

You just could group your functions and not use one functions.php file, do you really need to use all the functions at one push? include only those functions which are required in that execution and if you ask me 1000 lines is not a lot of lines..

Also, as I understand you don't use OOP, if you would use class'es with it's methods, it would be better, but slower of course, I think you could group your functions and use cache like the project Smart Cache which can boost your performance a lot, especially if you have lots of requests in one second.

Share this post


Link to post
Share on other sites

leave function definitions on separate file... only call functions when neededwhat i meant with source code... if it's an open source server like Apache - you can grab the source code and modify it so your functions gets included before you compile it! I don't know if this is possible but i'm just guessing...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.