전체 글
-
php 파일 예약 실행php 2023. 8. 30. 10:55
1. cron 작업 예약 -> unix 및 linux 시스템에서 crom 작업 예약을 사용하여 특정 시간에 스크립트를 실행할 수 있다. 1) 터미널을 열고 'crontab -e' 을 실행시켜 crontab 파일을 편집한다 20 8 * * * php /path/to/your/php/script.php -> 위의 경로에 원하는 파일을 삽입한다. 2. PHP 스크립트 내에서 슬립 사용 -> 슬립 함수를 사용해서 일정 시간동안 스크립트를 중지한 후 실행하는 방법 php를 실행하는 웹 서버가 항상 실행중이어야 하기 때문에 배포하지 않으면 실행하기 힘들다. // 현재 시간 정보 가져오기 $currentTimestamp = time(); // 목표 시간 설정 (매일 오전 8시 20분) $targetHour = 8; ..
-
php String Functionphp 2023. 8. 24. 08:30
1. strpos -> 문자열에서 부분 문자열이 처음 나타나는 위치를 찾는다 strpos ( string $haystack , string $needle , int $offset= 0 ): int | false https://secure.php.net/function.strpos PHP: strpos - Manual A pair of functions to replace every nth occurrence of a string with another string, starting at any position in the haystack. The first works on a string and the second works on a single-level array of strings, treating..
-
ssh 와 깃 허브php 2023. 8. 23. 19:50
1. ssh란? google remote (원격 데스크톱) -> 원격으로 들어가고싶으면 포트를 열어야한다 (랜덤한 포트) ssh 란? 구글 크롬(원격 데스크톱)과 비슷하며, 특히 리눅스에 연결하기 적합함 http 는 포트 80 // https 는 443 // ssh는 22 포트를 주로 사용한다 해커들이 랜덤한 ip를 무작위로 접근하는 것을 막기 가장 기본적인 방법이 포트를 변경해 주는 것 이다. C:\Users\admin\.ssh\config 와 같은 경로에 있는 config 파일에는 다음과 같이 ssh가 연결된 목록들을 확인할 수 있다 Host hostName HostName ip User user Port port IdentityFile "C:/key/exhi_key.pem" 위와같이 ip와 port..
-
php 경로 지정php 2023. 8. 21. 14:57
1. autoload 지정 다음과 같이 composer.json 내부의 autoload의 psr-4를 변경해서 경로를 지정할 수 있다. "APP\\DailyReportCrawler\\" : "src/" 란, APP\DailyReportCrawler 경로를 선언하면, 현재 composer.json이 있는 경로로 부터 가장 가까운 src/ 로 이동한다는 것을 뜻한다. 2. autoload 사용방법 위와 같이 autoload가 선언되어 있다면, 확장하고싶은 모듈의 상단에 namespace를 선언하고 모듈을 이용하고 싶은 곳에서 use 설정한경로\프로그램이름 을 선언하고 인스턴스 하는 것으로 모듈을 사용할 수 있다 use 로 클래스를 불러오면 클래스를 이용할 수 있게 된다. 만일 require "path" 를 ..
-
객체지향 프로그램 설계 ( SOLID )php 2023. 8. 21. 14:26
객체 지향 프로그램을 설계할 때 SOLID 5가지의 원칙을 지켜야 한다. SRP ( Single Responsibility Principle ) 단일 책임의 원칙 -> 모듈이 오직 하나의 액터에 대해서만 책임을 져야한다. ex) 비밀번호를 DB에 저장하는 기능 ( Membership ) 이 있다고 하면, 비밀번호를 받아서 DB에 넣는 모듈( RegistUser )과 비밀번호를 암호화 하는 모듈( EncodePass )을 따로 제작한다 OCP ( Open-Closed Principle ) 개방 폐쇄 원칙 -> 확장에 대해 열려있고 수정에 대해서는 닫혀있어야 한다는 원칙 확장에 대해 열려있다 : 요구사항이 변경될 때 새로운 동작을 추가하여 어플리케이션의 기능을 확장할 수 있음 수정에 대해 닫혀있다 : 기존의..
-
스크래퍼 제작하기php 2023. 8. 17. 11:18
curl / html 문법으로 get / post 방식의 request를 해서 데이터를 모아보자. 1. CrawlData.php 사용할 문서를 require로 불러오고 Class를 인스턴스 했다. composer로 다운받은 guzzle, css-selector를 사용하기 위해 vender 에 있는 autoload.php도 불러왔다. - 일반 get 방식 주가와 관련된 데이터는 휴일에는 갱신되지 않기 때문에, 날짜를 확인하는 함수를 먼저 실행시키고 url로 html을 불러온 다음, css-selector로 원하는 데이터의 경로를 특정할 수 있도록 제작했다. - curl get 방식 날짜 확인하는 부분이 생략되었지만 호출 부분에서 일반 get 방식과는 차이가 없다. - 모은 데이터들을 하나의 형태로 만들어서..