דילוג לתוכן
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום
כיווץ
תחומים

תחומים - פורום חרדי מקצועי

💡 רוצה לזכור קריאת שמע בזמן? לחץ כאן!
  1. דף הבית
  2. תכנות
  3. בקשת cURL לnginx שעובדת מהקונסול אבל לא מתוך PHP

בקשת cURL לnginx שעובדת מהקונסול אבל לא מתוך PHP

מתוזמן נעוץ נעול הועבר תכנות
20 פוסטים 4 כותבים 769 צפיות
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • chagoldC מנותק
    chagoldC מנותק
    chagold
    כתב ב נערך לאחרונה על ידי
    #11

    זה מוגדר עם php-fpm.

    image.png

    אבל הוא לא כותב ללוגים שלו כלום.
    לא בבקשה מהURL ולא מהPHP.

    תגובה 1 תגובה אחרונה
    0
    • chagoldC מנותק
      chagoldC מנותק
      chagold
      כתב ב נערך לאחרונה על ידי chagold
      #12

      רק עכשיו הצלחתי לגרום לו לכתוב את הלוגים של php-fpm.
      תכלס, הלוג מדפיס רק את הבקשה של @dovid את שלי הוא לא מדפיס.
      אבל במה שהוא מדפיס נוסף טקסט 'amp;' כמה פעמים.

      [26-Dec-2024 07:52:20 UTC] PHP Warning:  file_get_contents(http://g-in.com:200/index.php?format=json&p=chack_token_to_sp&Module=sub_projects&token_sub_project=kjsadouewio&token_user=AIAvo7yAhWqMrQJl271P&nick=administrator): Failed to open stream: HTTP request failed! in C:\xampp\file.php on line 339
      [26-Dec-2024 07:52:20 UTC] API call failed: Failed to get contents
      
      
      yossizY תגובה 1 תגובה אחרונה
      0
      • chagoldC מנותק
        chagoldC מנותק
        chagold
        כתב ב נערך לאחרונה על ידי chagold
        #13

        אבל לא התוים הנוספים הם הסיבה. כי עשיתי טסט בלי פרמטרים בכלל. ועדיין..

        [26-Dec-2024 08:08:38 UTC] PHP Warning:  file_get_contents(http://g-in.com:200/index.php): Failed to open stream: HTTP request failed! in C:\xampp\file.php on line 340
        [26-Dec-2024 08:08:38 UTC] API call failed: Failed to get contents
        
        תגובה 1 תגובה אחרונה
        0
        • yossizY מנותק
          yossizY מנותק
          yossiz
          השיב לchagold ב נערך לאחרונה על ידי
          #14

          @chagold כתב בבקשת cURL לnginx שעובדת מהקונסול אבל לא מתוך PHP:

          אבל לא התוים הנוספים הם הסיבה. כי עשיתי טסט בלי פרמטרים בכלל. ועדיין..

          [26-Dec-2024 08:08:38 UTC] PHP Warning:  file_get_contents(http://g-in.com:200/index.php): Failed to open stream: HTTP request failed! in C:\xampp\file.php on line 340
          [26-Dec-2024 08:08:38 UTC] API call failed: Failed to get contents
          

          יש לך שני אתרי PHP אם הבנתי נכון, ואתה מנסה לעשות קריאה מאחד לשני
          הלוג פה מראה רק את הקריאה של file_get_contents
          האם אתה בטוח שהאתר השני (g-in.com:200) גם עובר דרך php-fpm?

          אם לא, אז מה כן?
          אתה יכול להראות את הקונפיגרציה של השרת אפאצ'י או nginx?

          📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

          תגובה 1 תגובה אחרונה
          0
          • chagoldC מנותק
            chagoldC מנותק
            chagold
            כתב ב נערך לאחרונה על ידי chagold
            #15

            זה לוג רק של שגיאות.
            הוא נוצר באמצעות הקוד הזה -

            c:\tools\nssm.exe set PHP-FPM AppParameters "-b 127.0.0.1:9000 -d error_log=C:/php/logs/php-fpm.log -d display_errors=1 -d log_errors=1 -d error_reporting=E_ALL"
            

            לא הצלחתי לעשות לוג של כל הבקשות

            # nginx.conf - Combined Configuration
            
            worker_processes  1024;
            
            error_log  "C:/nginx/logs/error.log";
            #error_log  logs/error.log  notice;
            #error_log  logs/error.log  info;
            
            events {
                worker_connections  1024;
            }
            
            http {
                include       "C:/nginx/conf/mime.types";
                
            
                default_type  application/octet-stream;
                charset utf-8;
                log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                                 '$status $body_bytes_sent "$http_referer" '
                                 '"$http_user_agent" "$http_x_forwarded_for"';
            
                log_format  debug  '$remote_addr - $remote_user [$time_local] "$request" '
                               '$status $body_bytes_sent "$http_referer" '
                               '"$http_user_agent" "$http_x_forwarded_for" '
                               'rt=$request_time ua="$upstream_addr" '
                               'us="$upstream_status" ut="$upstream_response_time" '
                               'ul="$upstream_response_length" '
                               'cs=$upstream_cache_status';
            
            access_log  logs/access.log  debug;
            
                access_log  "C:/nginx/logs/access.log"  main;
            
                sendfile        on;
                keepalive_timeout  65;
            
                # FastCGI Settings
                fastcgi_buffers 8 16k;
                fastcgi_buffer_size 32k;
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
            
                # Default server (port 80)
                server {
                    charset utf-8;
                    listen 80;
                    server_name localhost;
                    root C:/xampp/reko;
                    
                    location / {
                        index index.php index.html index.htm;
                        try_files $uri $uri/ /index.php?$args;
                        autoindex on;
                    }
            
                    error_page   500 502 503 504  /50x.html;
                    location = /50x.html {
                        root   html;
                    }
            
                    location ~ \.php$ {
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;
                    }
                }
            
                # Port 200 server (reko)
                server {
                    listen 200;
                    server_name localhost;
                    root C:/xampp/reko;
                    
                    location / {
                        index index.php index.html index.htm;
                        try_files $uri $uri/ /index.php?$args;
                        autoindex on;
                        proxy_connect_timeout 10;
                        proxy_send_timeout 10;
                        proxy_read_timeout 10;
                    }
            
                    error_page   500 502 503 504  /50x.html;
                    location = /50x.html {
                        root   html;
                    }
            
                    location ~ \.php$ {
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;
                    }
                }
            
            
            }
            

            והקונפיגורציה של php-fpm

            [global]
            pid = C:/nginx/php-fpm.pid
            error_log = C:/php/logs/php-fpm.log
            
            [www]
            listen = 127.0.0.1:9000
            listen.allowed_clients = 127.0.0.1
            user = nobody
            pm = dynamic
            pm.max_children = 5
            pm.start_servers = 2
            pm.min_spare_servers = 1
            pm.max_spare_servers = 3
            access.log = C:/php/logs/php-fpm-access.log
            catch_workers_output = yes
            
            תגובה 1 תגובה אחרונה
            1
            • chagoldC מנותק
              chagoldC מנותק
              chagold
              כתב ב נערך לאחרונה על ידי
              #16

              התקרבתי לפתרון. לא יודע איך לחצות את הגשר.
              ניסיתי לבדוק אם הPHP יריץ את הפקודה cmd זה כן יעבוד. והתברר שהבקשה עצמה תקינה, (והיא גם מדפיסה את התגובה לקובץ c:\url_response.txt), היא רק לא מחזירה את הפלט לתוכנת הPHP שביקשה אותה.
              זה הפקודה

                  function createFullSystem() {
                      $urlFile = 'C:\\url_command.txt';
                      $batchFile = 'C:\\url_runner.bat';
                      $outputFile = 'C:\\url_response.txt';
                      
                      $url = "http://g-in.com:200/index.php?" . http_build_query([
                          'format' => 'json',
                          'p' => 'chack_token_to_sp',
                          'Module' => 'sub_projects',
                          'token_sub_project' => 'kjsadouewio',
                          'token_user' => 'AIAvo7yAhWqMrQJl271P',
                          'nick' => 'administrator'
                      ]);
                      
                      file_put_contents($urlFile, $url);
                      
                      $batchContent = "@echo off\n";
                      $batchContent .= "cd C:\\tools\n";
                      $batchContent .= "set /p URL=<" . $urlFile . "\n";
                      // בדיוק אותה פקודה שעובדת ב-CMD
                      $batchContent .= "C:\\Windows\\System32\\curl.exe -v -H \"User-Agent: PHP/cURL\" --connect-timeout 10 -m 10 \"%URL%\" > " . $outputFile . " 2>&1\n";
                      $batchContent .= "exit\n";
                      
                      file_put_contents($batchFile, $batchContent);
                      
                      $descriptorspec = array(
                          0 => array("pipe", "r"),
                          1 => array("pipe", "w"),
                          2 => array("pipe", "w")
                      );
                      
                      $process = proc_open("cmd /c " . $batchFile, $descriptorspec, $pipes);
                      
                      if (is_resource($process)) {
                          stream_set_blocking($pipes[1], 0);
                          stream_set_blocking($pipes[2], 0);
                          
                          $start = time();
                          $timeout = 1;
                          
                          do {
                              $status = proc_get_status($process);
                              if (!$status['running']) {
                                  break;
                              }
                              if (time() - $start > $timeout) {
                                  proc_terminate($process);
                                  echo "Process terminated due to timeout\n";
                                  break;
                              }
                              sleep(1);
                          } while (true);
                          
                          fclose($pipes[0]);
                          fclose($pipes[1]);
                          fclose($pipes[2]);
                          proc_close($process);
                      }
                      
                      if(file_exists($outputFile)) {
                          echo "Response from server:\n";
                          echo file_get_contents($outputFile);
                      }
                  }
              
              yossizY תגובה 1 תגובה אחרונה
              1
              • yossizY מנותק
                yossizY מנותק
                yossiz
                השיב לchagold ב נערך לאחרונה על ידי yossiz
                #17

                @chagold כתב בבקשת cURL לnginx שעובדת מהקונסול אבל לא מתוך PHP:

                התקרבתי לפתרון

                אני לא יודע כמה זה מקדם אותנו, כי מה שהסקריפט עושה הוא בדיוק כמו להריץ פקודת curl ידנית. וזה ידענו כבר שעובד.

                יש משהו מוזר פה

                נסה לעבוד עם file_get_contents ולבדוק אם זה עובד בשום צורה

                📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

                תגובה 1 תגובה אחרונה
                0
                • yossizY מנותק
                  yossizY מנותק
                  yossiz
                  כתב ב נערך לאחרונה על ידי yossiz
                  #18

                  נראה לי שמצאתי את התשובה!!

                  https://stackoverflow.com/a/13814609/8997905

                  (אני רק לא מבין אם ככה למה זה כן עובד 🤔 )

                  אם זו באמת הבעיה, תחפש מדריך רשמי של PHP איך להקים שרת בסביבת ווינדוס בצורה נכונה והבעיה אמורה להיפתר
                  למשל זה: https://www.php.net/manual/en/install.windows.apache2.php
                  (ותוודא שיש לך גירסאות מעודכנות של הכלים)

                  מישהו כתב פה פתרון לnginx על ווינדוס

                  📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

                  תגובה 1 תגובה אחרונה
                  2
                  • chagoldC מנותק
                    chagoldC מנותק
                    chagold
                    כתב ב נערך לאחרונה על ידי chagold
                    #19

                    @yossiz תודה רבה!
                    זנ כנראה לא הבעיה. (והא ראיה שעבד לי הגישה לcmd).
                    אבל לו הייתי יודע על הפוסט בסטאק הייתי מראש מוותר על nginx בלוקאלי. (או מתקין לינוקס בלוקלי?😕 ).
                    עכ"פ חזרתי עכשיו לאפאצי שהיה לי, ונראה אם אני יסתדר בהמשך.

                    תגובה 1 תגובה אחרונה
                    1
                    • Aharon 0A מנותק
                      Aharon 0A מנותק
                      Aharon 0
                      כתב ב נערך לאחרונה על ידי
                      #20

                      תתחיל מזה שתשנה את הפורט מ 200 למעל 1024, וחוץ מזה תבדוק שאתה לא נופל על פורט שמור:
                      https://www.geeksforgeeks.org/50-common-ports-you-should-know/

                      תגובה 1 תגובה אחרונה
                      -1

                      בא תתחבר לדף היומי!
                      • התחברות

                      • אין לך חשבון עדיין? הרשמה

                      • התחברו או הירשמו כדי לחפש.
                      • פוסט ראשון
                        פוסט אחרון
                      0
                      • דף הבית
                      • קטגוריות
                      • פוסטים אחרונים
                      • משתמשים
                      • חיפוש
                      • חוקי הפורום