PHP 의 잘못된 코드로 인해 서버중단을 막으려면..

망치의 이미지

PHP 에서 잘못된 코드로인해 무한루프를 돌기시작하면 혼자 메모리 다 긁어먹고 스왑까지 다 빨아먹어버리더군요.. 서버는 거의 죽기직전까지 가고.. =_=;

이걸 효과적으로 예방할 방법.. 뭐가 있을까요? 물론 잘못된 코드를 실행하지 못하도록 하는게 최선이겠지만, 2차적으로 혼자 메모리를 엄청 먹어대면 강제로 종료시킨다거나 할 방법 없을까요?

kall의 이미지

환경설정에서 memory_limit 옵션으로 안되나요?
설정되어 있으면 설정된 한계치 까지만 먹고 그 이상 먹을경우는
메모리 부족 에러내고 종료될텐데요..

----
자신을 이길 수 있는자는
무슨짓이든 할수있다..
즉..무서운 넘이란 말이지 ^-_-^
나? 아직 멀었지 ㅠㅠ

preisner의 이미지

php.ini 에서 memory_limit 를 설정 해 주어도 되고요,
리눅스에서 ulimit 를 이용해서 프로세스별로 자원 한계를 줄수도 있습니다.
자세한 내용은 도움말을 참고하세요.

망치의 이미지

memory_limit 8M 으로 설정되어있는 상태인데 소용이 없습니다..

ulimit 외에 php 나 apache 설정으로는 힘들까요?

---------------------------------------
http://www.waitfor.com/
http://www.textmud.com/

송효진의 이미지

PHP 만으로는 ini 설정을 벗어나도록 메모리를 먹지 못할것으로 생각됩니다.
실행되는 프로그램이 exec 하는것 아닌가요?
아니면 해당 php 프로세스가 권한이 너무 많은것은 아닌가요?

망치의 이미지

테스트용으로 임의로 만든 무한루프입니다. 열심히 돌면서 스왑메모리까지 다 먹어대는데, 프로세스 안죽고 잘 돌아가더군요..

분명 php.ini 에선, memory_limit 가 8M 으로 잡혀있는데도요. 혹시 젠드와 관련이 있을까요?

<?
    $n = 0;
    while(true){
        $x[$n] = $n;
        $n++;
    }
?>

---------------------------------------
http://www.waitfor.com/
http://www.textmud.com/

nainu의 이미지

400M 정도 되는 테이블의 자료를 모두 배열에 넣어보세요.. 잘 뻗습니다..
혹은, phpmyadmin 에 큼지막한 sql.gz 파일을 넣어도 메모리 풀은 잘 일어나죠..

정태영의 이미지

Quote:
cafri php-5.0.4 # ./configure --help|grep memory
--enable-sysvshm Enable the System V shared memory support.
--enable-memory-limit Compile with memory limit support.

--enable-memory-limit 옵션이 활성화되었는지 모르겟군요 :)

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

망치의 이미지

웃.. -_- 가장 기본적인걸 놓쳤군요.. :oops:
configure 설정해두었던걸 보니 해당 옵션이 빠져있네요.. 다시 컴파일중입니다;;;

감사합니다 :lol:

---------------------------------------
http://www.waitfor.com/
http://www.textmud.com/

정태영의 이미지

결과가 궁금하네요 :)

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

망치의 이미지

컴파일이 상당히 오래 걸리네요.
이 옵션 추가로 뭔가 확 늘어난듯한 느낌입니다.

금방 테스트를 마쳤고 이제 원하는대로 작동합니다.

Quote:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 524288 bytes) in /home/***/www/test/test.php on line 5

태영님께 이래저래 도움을 자주 받네요. 감사드립니다. :lol:

---------------------------------------
http://www.waitfor.com/
http://www.textmud.com/

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.