Hello to all.

Previous question using HTTP proxy . Now! How to save the page content? Those. cache pages and store them in a folder. Found a function in the internet:

CURLOPT_DNS_USE_GLOBAL_CACHE TRUE to use the global DNS cache. This option is not thread safe and is enabled by default.

How to work with this function?

Still found:

By default, it’s not a bad idea.

An example of the function, maybe it does not apply, but still give.

  // Определить папку для хранения кэшированных данных define ('CACHE_DIR',dirname(__FILE__).'/cache'); // Запись данных в кэш function save_cache($file, $data) { if ($f=fopen(CACHE_DIR.'/'.$file,'w')) { fwrite($f,serialize($data)); fclose($f); return true; } else { return false; } } 
  • The question is closed! - marioxxx

1 answer 1

You mix flies with meatballs, and add cockroaches to the general heap.

firstly about: CURLOPT_DNS_USE_GLOBAL_CACHE Any domain name (tobish address) is transferred to ip address, so that would not do nslookup constantly, this data is cached, for example, it is remembered that for google.com ip address - 173.194.35.37 to the page is no relation It has!

Secondly, a caching proxy is a caching proxy and php has nothing to do with it. You simply make a request for a page through a caching proxy server, and he himself will perform caching operations.

The code you gave is an attempt to cache it yourself. It seems normal, but I would do a little differently, something like (pseudocode):

 function getPage($page) { if (есть файлик $page в кеше) { return file_get_contents(CACHE.'/'.$page); } $content = curlGetPage($page); saveToCache($page, $content); return $content; } 

Tobish the getPage function checks the cache, if the cache in the cache is not present, it loads via the cursor and saves it to the cache, the next time the same request is taken from the cache.

In general, the question is rather abstract and vague. So I find it difficult to give a sane answer

  • Where did you get the savetocache function? From my example? - marioxxx
  • This is pseudocode, tobish only an explanation of the order of actions. but in general, your function will work fine - Alex Kapustin
  • aa is clear with pseudocode - marioxxx