スキップしてメイン コンテンツに移動

投稿

ラベル(cURL)が付いた投稿を表示しています

Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.

composer install コマンドを実行したところ下記の警告メッセージが表示されました。 Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled. PHPのcurl extensionが有効でないため、Composerが通常より遅くなると言われているので、PHPのcurl extensionをインストールします。 実際、curl extensionをインストールしないと遅くなりました。 Linuxのディストリビューションに応じて下記のコマンドを実行して、PHPのcurl extensionをインストールします。 apt install php-curl yum install php-curl Windowsの場合は、php.iniを編集してcurl extensionを有効化します。 php.iniの場所は php --ini をPoweerShellやコマンドプロンプトで実行すればわかります。 php.ini内の Loaded Configuration File: 付近で下記の行のコメントを削除して、有効化します。 extension=php_curl.dll

PHPでCurlを使ってファイルをダウンロード

PHPでcurlを使ってネットワーク上からファイルをダウンロードするサンプルコードです。 用途に応じてカスタマイズして使ってみてください。 Curlの実行クラス(メモリ上に展開とファイルに直接ダウンロードするメソッド) <?php namespace Util\Net; class Curl { // 引数の$optionsで設定をカスタマイズ可能 public static function request($url, $options): CurlResponse { return self::execCrul($url, $options + [ CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, // 例: 5回までリダイレクト許可 CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, // 例: タイムアウト3秒 CURLOPT_TIMEOUT => 3, CURLOPT_CONNECTTIMEOUT=> 3, // 例: sslのエラーを無視 (安全性下がるのでよくない) CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, ]); } // curlの実行結果を直接ファイルにダウンロードする public static function downloadAsFile($url, $storePath, $options): CurlResponse { $fp = fopen($storePath, 'w+');

Get Youtube Information by PHP cURL

I have written small code snippet for getting information from Youtube by PHP with cURL! The code itself is nothing special, really straightforward manner. The following getVideoInfo function takes youtube video id, access to youtube api and return back the detail video information. function getVideoInfo($id) { try { $req = request('http://gdata.youtube.com/feeds/api/videos/' . $id); $xmlStr = $req->getResponseData(); $xml = simplexml_load_string($xmlStr); $xml->registerXPathNamespace('x', 'http://www.w3.org/2005/Atom'); $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/'); $xml->registerXPathNamespace('yt', 'http://gdata.youtube.com/schemas/2007'); $title = $xml->xpath('/x:entry/media:group/media:title'); $duration_seconds = $xml->xpath('/x:entry/media:group/yt:duration/@seconds'); if (empty($title