1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

インターネッツのファイルの更新日時を取得する

Last updated at Posted at 2019-08-13

とある kenkooooさんのAtCoderProblems の Datasetが更新されたら取得する、というプログラムを組もうと思いました。

どうやったら更新情報を取得できるのか…… :thinking:

file_get_contents使うと $http_response_header がついてくるよ

という情報があったんですが、file_get_contents使っちゃうとなぁ…… 目的のデータは460MB以上 なんだよねぇ…… :sweat_smile:

更新情報を取得するためだけに何度も460MBの転送を発生させてしまうと、kenkooooさんに戦車砲 :bomb: でやられてしまうような気がしたので、別の方法を。

get_headers()

get_headers を使います。
get_headers を使って、 $http_response_header と同等の情報を取得します。
ヘッダ情報取得だけなので、本体をダウンロードする必要はありません。
file_get_contentsを使うと45秒ほどかかりましたが、 get_headersの方なら約0.2秒でした)
ヘッダ情報の中の、 Last-Modified が最終更新日時です。

サンプル

<?php
    $url = "https://s3-ap-northeast-1.amazonaws.com/kenkoooo/atcoder.sql";

    $data = get_headers($url, 1);
    $time_modify = $data['Last-Modified'];
    echo date("Y-m-d H:i:s", strtotime($time_modify));
  • 実行結果
2019-08-13 03:42:06
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?