LF-DevJourney
LF-DevJourney

Reputation: 28564

PHP how to avoid load source file on each request?

I have the below API. CityData.php is a file with city and zip which has a size of 100kb. With this function the interpreter loads the file from disk to memory on each request. How can I avoid this and share it between requests?

<?php
    require_once 'Config.php';
    class CourseController{
        public function getCourseApi()
        {
            require_once 'CityData.php';
            ......
        }
    }

CityData.php

  130433 => '馆陶县',
  130434 => '魏县',
  130435 => '曲周县',
  130481 => '武安市',
  130500 => '邢台市',
  130502 => '桥东区',
........

Upvotes: 0

Views: 170

Answers (1)

Odai Nasser
Odai Nasser

Reputation: 112

Mem Cash is a good solution you can load data for one time then it will available in the RAM for how long you want.

Upvotes: 1

Related Questions