質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

MAMP

Mac 上で WordPress などの動的ページのサイトが作れるように環境を構築するフリーソフト

Q&A

解決済

1回答

4398閲覧

MAMPのapacheのTimeoutを伸ばす

SoraSue

総合スコア30

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

MAMP

Mac 上で WordPress などの動的ページのサイトが作れるように環境を構築するフリーソフト

0グッド

0クリップ

投稿2017/09/17 01:59

###前提・実現したいこと
mampのローカル開発環境でpythonをcgiとして実行しているのですが、タイムアウトしてしまいます。そのため、mampのapacheのタイムアウトを伸ばしたいです。

###発生している問題・エラーメッセージ
pythonをcgiとして実行させると、apacheのエラーログに次のようなエラーが出ます。

 [error] [client ::1] (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed

###該当のソースコード
以下のコードを実行させました。内容は、「chrome拡張機能としてユーザーが訪れたページの本文を取得→それをmecabで形態素解析→mysqlにURLと単語をそれぞれ保存→mysqlから過去のデータを取得してtf-idf(その単語の重要度)を単語ごとに計算」というものです。Lifehackerなどではタイムアウトしませんでしたが、wikipediaなど少し長いサイトになるとタイムアウトします。

python

1#!/Users/僕のユーザー名/.pyenv/versions/anaconda3-4.4.0/bin/python 2# -*- coding: utf-8 -*- 3 4import sys,io,codecs 5 6print("Content-Type: text/html; charset=UTF-8") 7print() 8 9sys.stdin = open('/dev/stdin', 'r', encoding='UTF-8') 10sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) 11 12import cgi 13import cgitb; cgitb.enable() 14import json 15from readability.readability import Document 16import urllib.request 17import html2text 18import MeCab 19import mysql.connector 20import re 21import math 22import socket 23socket.setdefaulttimeout(1800) 24print(str(socket.getdefaulttimeout())) 25 26def save(url,word): 27 config = { 28 'user': 'root', 29 'password': 'root', 30 'unix_socket': '/Applications/MAMP/tmp/mysql/mysql.sock', 31 'database': 'hoge', 32 'raise_on_warnings': True, 33 } 34 link = mysql.connector.connect(**config) 35 cursor = link.cursor() 36 37 cursor.execute('''insert into horizon (url,text) values (%s,%s)''', [url,word]) 38 link.commit() 39 40def tf_idf(url,words): 41 all_words_in_this_site = len(words) 42 config = { 43 'user': 'root', 44 'password': 'root', 45 'unix_socket': '/Applications/MAMP/tmp/mysql/mysql.sock', 46 'database': 'hoge', 47 'raise_on_warnings': True, 48 'connection_timeout': 1800 49 } 50 link = mysql.connector.connect(**config) 51 cursor = link.cursor(buffered=True) 52 53 cursor.execute('select max(id) from horizon') 54 all_texts = cursor.fetchone()[0] 55 print(type(all_texts)) 56 print(all_texts) 57 for word in words: 58 word_in_this_site = 0 59 if word in words: 60 word_in_this_site = word_in_this_site + 1 61 else: 62 word_in_this_site = word_in_this_site 63 tf = word_in_this_site/all_words_in_this_site 64 cursor.execute('select url from horizon where text = %s',(word,)) 65 texts_with_word = cursor.rowcount 66 idf = math.log(all_texts/texts_with_word)+1 67 tf_idf = tf * idf 68 print(word) 69 print(tf_idf) 70 link.commit() 71 72def cut_text(text): 73 text = text.strip("") 74 text = text.replace("http","") 75 text = text.replace("/","") 76 text = text.replace("[","") 77 text = text.replace("]","") 78 text = text.replace("%","") 79 text = text.replace(" ","") 80 text = text.replace("{","") 81 text = text.replace("}","") 82 text = text.replace("%","") 83 text = text.replace(":","") 84 text = text.replace("#","") 85 text = text.replace("*","") 86 text = text.replace("\n","") 87 text = text.replace("|","") 88 text = text.replace("-","") 89 text = text.replace(".","") 90 text = text.replace("?","") 91 text = text.replace("(","") 92 text = text.replace(")","") 93 text = text.replace("<","") 94 text = text.replace(">","") 95 text = text.replace("¥¥","") 96 text = text.replace("¥n","") 97 text = text.replace("1","") 98 text = text.replace("2","") 99 text = text.replace("3","") 100 text = text.replace("4","") 101 text = text.replace("5","") 102 text = text.replace("6","") 103 text = text.replace("7","") 104 text = text.replace("8","") 105 text = text.replace("9","") 106 text = text.replace("0","") 107 text = text.replace("@","") 108 109 text = text.replace("\◆","") 110 text = text.replace("◆","") 111 text = text.replace("\0","") 112 text = text.replace("\a","") 113 text = text.replace("\b","") 114 text = text.replace("\t","") 115 text = text.replace("\n","") 116 text = text.replace("\v","") 117 text = text.replace("\f","") 118 text = text.replace("\r","") 119 text = text.replace("\e","") 120 text = re.sub(r'[\x00-\x1f\x7f]+', '', text) 121 122form = cgi.FieldStorage() 123for key in form.keys(): 124 url = form.getvalue(key) 125 html = urllib.request.urlopen(url) 126 s = html.read() 127 128 article = Document(s).summary() 129 article = article.encode("utf-8") 130 article = article.decode("utf-8") 131 132 text = html2text.html2text(article) 133 cut_text(text) 134 tagger = MeCab.Tagger('-d ./mecab-ipadic-neologd') 135 tagger.parse('') 136 node = tagger.parseToNode(text) 137 words = [] 138 while node: 139 surface = node.surface 140 words.append(surface) 141 node = node.next 142 for word in words: 143 save(url,word) 144 145 tf_idf(url,words)

###試したこと
上のコードにもあるように、socket.setdefaulttimeout(1800)や'connection_timeout': 1800でタイムアウトを伸ばそうとしてみました。しかし、実行してもすぐにタイムアウトしたので、mampのapacheのtimeoutについての設定に原因があるのだと思います。これを変えるために、httpd.confを見てみましたが、timeoutについての記述が見つかりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境は以下の通りです。

  • macOS Sierra
  • python3
  • MAMP バージョン4.2

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

/Applications/MAMP/conf/apache/extra/httpd-default.conf

上記ファイルに TimeOut の設定が記載されているのではないかと思います。
該当箇所があれば、TimeOut ディレクティブに変更したい秒数を指定します。
設定の詳細は下記のドキュメントを参照してください。

https://httpd.apache.org/docs/2.2/ja/mod/core.html#timeout

投稿2017/09/19 12:10

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

SoraSue

2017/09/21 10:51

変更できました!教えていただきありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問