2009-06-26 4 views
3

Webページ(自分のサイト)から情報を取得し、特定の情報を検索するための最良の方法テキスト。fopen()またはfile_get_contents()を使用してWebページを取得するためのベストプラクティス

PHP/Joomlaを実行するサーバの中にはcURLを有効にしていないものがあることに注意してください。予期しないエラーは発生したくありません。

私はfopen()とfile_get_contents()の両方を見てきましたが、どちらもcURLの有無にかかわらず互いに矛盾するビューを持っているようです。

答えて

4

これらはどちらもカールしないで動作しますが、allow_url_fopenを有効にする必要があります。 phpinfo()を実行することで確認できます。セキュリティへの影響は、しかしあり、これを参照してください。

Should I allow 'allow_url_fopen' in PHP?

だからページをつかむために、あなたは fopen(を使用することができます)、 file_get_contents()またはPHPで実装いくつかの他の独立したHTTPクライアントそれらなしで機能できるような HttpClient

1
I read now and then on forums and chats that allow_url_fopen has to be enabled for Joomla to work properly. That's an "urban legend", leftover from old versions, but almost no one seems to actually test and confirm that fact. It seems the Docs are also wrong about it. 

Joomla! CMS & Framework don't depend on "allow_url_fopen" being enabled. Period! 

Quite the contrary, J! Framework has a very good and robust core subpackage HTTP, which supports "drivers" based on cURL, streams and sockets. Which means even with fopen() URL wrappers ("streams" driver) disabled altogether ("allow_url_fopen = 0"), any extensions implementing HTTP subpackage still has "cURL" and "sockets" driver available. For example, Joomla Update component will, in case "allow_url_fopen" is disabled, fall back on using cURL wrapper (given cURL PHP extension is enabled). 
+0

ヒント:アップフォースに興味がある場合は、人間が判読できるテキストをよく書くことを検討してください。あなたは、段落を使うのと同じように、*マークアップ*を使って物を強調するのが好きです。そのような判読不能な混乱を避ける代わりに。 – GhostCat

+0

ありがとう@GhostCat –

+0

それは今より良いです。 4つのスペースのコードブロックインデントを使用するポイントは何ですか? – GhostCat

関連する問題