Skip to main content
Tighten up post a little.
Source Link
Martijn Pieters
  • 14.7k
  • 10
  • 60
  • 59

Frequent file system writes in phpPHP when serializing objects

I am building a game based on PHP and MySQL. Basically thereThere is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

Basically itIt is a combat type of game where players have up to two characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb, but it is just bugging me so bad. What are your thoughts on this, I'm open for advice.?

Frequent file system writes in php when serializing objects

I am building a game based on PHP and MySQL. Basically there is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

Basically it is a combat type of game where players have up to two characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb, but it is just bugging me so bad. What are your thoughts on this, I'm open for advice.

Frequent file system writes in PHP when serializing objects

I am building a game based on PHP and MySQL. There is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

It is a combat type of game where players have up to two characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb. What are your thoughts on this?

Change "sterilizing" to "serializing"
Link

Frequent file system writes in php when sterilizingserializing objects

Spell out small numbers. Change tagged title format. Add sterilization tag. Remove 'Thanks!'
Source Link
user40980
user40980

PHP: frequent Frequent file system writewrites in php when sterilizing objects

I am building a game based on PHP and MySQL. Basically there is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

Basically it is a combat type of game where players have up to 2two characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading 2two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb, but it is just bugging me so bad. What are your thoughts on this, I'm open for advice. Thanks!

PHP: frequent file system write

I am building a game based on PHP and MySQL. Basically there is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

Basically it is a combat type of game where players have up to 2 characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading 2 files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb, but it is just bugging me so bad. What are your thoughts on this, I'm open for advice. Thanks!

Frequent file system writes in php when sterilizing objects

I am building a game based on PHP and MySQL. Basically there is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.

Basically it is a combat type of game where players have up to two characters and can fight each other, taking turns.

I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.

However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.

Here's the unit class

class Unit {
    // Generic
    protected $id = null;
    public function getID(){ return $this->id; }

    public $owner = null;
    public $name;

    // Vitality
    public $HP          = 100;
    public $HPmax       = 100;
    public $energy      = 100;
    public $NRGmax      = 100;

    // Physical
    public $strength    = 0;
    public $endurance   = 0;

    // Psychical
    public $knowledge   = 0;
    public $wisdom      = 0;

   // ...
}

And here's how the file structure looks like

/PvC/prototypes/
/PvC/clones/

in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units) which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.

In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.

I know this is not really something that would matter, as file size will rarely exceed 10kb, but it is just bugging me so bad. What are your thoughts on this, I'm open for advice.

edited body
Source Link
php_nub_qq
  • 2.2k
  • 5
  • 21
  • 25
Loading
Source Link
php_nub_qq
  • 2.2k
  • 5
  • 21
  • 25
Loading