Skip to content

Instantly share code, notes, and snippets.

@co3k
Created July 2, 2010 15:47
Show Gist options
  • Save co3k/461539 to your computer and use it in GitHub Desktop.
Save co3k/461539 to your computer and use it in GitHub Desktop.
<?php
/*
usage:
/usr/bin/php /path/to/this/script.php >> /tmp/junkai-log
*/
date_default_timezone_set('Asia/Tokyo');
$target_base = 'http://example.com/pc_frontend_dev.php/';
$targets = array(
'', 'member/home', 'album', 'album/listMember', 'album/listFriend',
'ashiato/list', 'community/search', 'community/1',
'community/member/list?id=1', 'community/joinlist', 'communityTopic/search',
'communityTopic/listCommunity/1', 'communityTopic/recentlyTopicList',
'communityTopic/search?type=event', 'communityEvent/1', 'communityEvent/1/memberList',
'communityEvent/listCommunity/1', 'communityEvent/recentlyEventList',
'community/search', 'diary', 'diary/listFriend', 'diary/listMember',
'diary/1', 'diary/comment/history', 'diary/search',
'friend/list', 'friend/showImage/1', 'friend/manage',
'member/1', 'member/profile', 'member/search', 'member/search?member[name]=a',
);
login($target_base);
echo '['.date('Y-m-d H:i:s').']Begin junkai'.PHP_EOL;
foreach ($targets as $target)
{
$url = $target_base.$target;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie');
$output = curl_exec($ch);
$info = curl_getinfo($ch);
// レスポンスコードが 200 以外、もしくは </html> がない場合
if (200 != $info['http_code'] || !strpos($output, '</html>'))
{
$filename = '/tmp/200janai-'.str_replace('/', '_', $target).'.'.date('YmdHis');
file_put_contents($filename, $output);
echo 'F ('.$filename.')';
}
else
{
echo '.';
}
curl_close($ch);
sleep(1);
}
echo PHP_EOL;
echo '['.date('Y-m-d H:i:s').']Finish junkai'.PHP_EOL;
function login($target_base)
{
$url = $target_base.'member/login/authMode/Example';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'auth%5Bmail_address%5D=sns1%40example.com&auth%5Bpassword%5D=password&auth%5Bnext_uri%5D=member%2Fhome');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie');
$result = curl_exec($ch);
if (!$result)
{
var_dump('curl error:', curl_error($ch));
}
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment