php simplehtmldom 사용시에 file_get_contents(): SSL operation failed with code 1 오류 발생시 해결 방법
페이지 정보

본문
## 현상
simplehtmldom 을 사용해서 https url 을 가져올 때에 아래와 같은 오류가 난다.
```
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed ....
Warning: file_get_contents(): Failed to enable crypto in ....
Warning: file_get_contents(....): Failed to open stream: operation failed in ....
```
## 해결법
simple_html_dom.php 파일을 열어서,
$contents = file_get_contents( 구문 위에 아래와 같은 $context 를 만들어주는 구문을 추가해 준다.
```
$opts = array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$context = stream_context_create($opts);
$contents = file_get_contents(
$url,
$use_include_path,
$context,
$offset,
$maxLen
);
```
## 참고
https://www.php.net/manual/en/function.file-get-contents.php
https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-failed-to-enable-crypto
simplehtmldom 을 사용해서 https url 을 가져올 때에 아래와 같은 오류가 난다.
```
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed ....
Warning: file_get_contents(): Failed to enable crypto in ....
Warning: file_get_contents(....): Failed to open stream: operation failed in ....
```
## 해결법
simple_html_dom.php 파일을 열어서,
$contents = file_get_contents( 구문 위에 아래와 같은 $context 를 만들어주는 구문을 추가해 준다.
```
$opts = array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$context = stream_context_create($opts);
$contents = file_get_contents(
$url,
$use_include_path,
$context,
$offset,
$maxLen
);
```
## 참고
https://www.php.net/manual/en/function.file-get-contents.php
https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-failed-to-enable-crypto
추천0
댓글목록
등록된 댓글이 없습니다.