Menu

Reading result while running PHP

2009-01-26
2013-04-22
  • Wesley Milan

    Wesley Milan - 2009-01-26

    I have to lengthy scripts to run, and I need to now what´s happening while run.  In browser I can see parts of results while PHP are running but in psvPHP I cant.
    How can I make psvPHP send a partial result to a Memo for exemple?

    Thanks anyone.

     
    • Nobody/Anonymous

      Hi

      1. Copy DelphiFunctions.pas and php4delphi.pas from component folder to the your project folder and adding both to your main project.

      2. Add to this module you new function eg :

      // ----------------------------- delphi_addline_memoa
      //add line to memo in runtime mode
      {$IFDEF PHP510}
      procedure delphi_addline_to_memo(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
            return_value_used : integer; TSRMLS_DC : pointer); cdecl;
      {$ELSE}
      procedure delphi_addline_to_memo(ht : integer; return_value : pzval; this_ptr : pzval;
            return_value_used : integer; TSRMLS_DC : pointer); cdecl;
      {$ENDIF}

      var str : string;
        Param : pzval_array;
      begin
        if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
        begin
          zend_wrong_param_count(TSRMLS_DC);
          Exit;
        end;
        try
        convert_to_string(param[0]^);
        str:=param[0]^.value.str.val;

      MainForm.Memo1.Lines.Add(Str); // add string to memo line
      Application.ProcessMessages; // refresh display

      finally
      ZVAL_BOOL(return_value,true);
      end;
      end;

      3.Add this function info to module php4delphi.pas :

      procedure php_info_library(zend_module : Pointer; TSRMLS_DC : pointer); cdecl;
      var
      cnt : integer;
      begin
        php_info_print_table_start();
      ...
      ...
      ...
      php_info_print_table_row(2, 'delphi_addline_to_memo', 'Dodaje linie do pola zaklady');
      ...
      ...

      4. For new function Add Entry table in module delphi4php.pas :

      procedure TPHPEngine.RefreshLibrary;
      var
      cnt : integer;
      begin
        SetLength(FLibraryEntryTable, FHash.Count + XX); // Add 1 to length entry table for new function
      ...
      ...
      ...
      PHP_FUNCTION(FLibraryEntryTable[XX], 'delphi_addline_to_memo', @delphi_addline_to_memo);
      ...
      end;

      for display any line from your script use you new function in php code:

      <?php
      delphi_addline_to_memo("Hello world, this is begin of my script");
      ...
      ...
      ...
      delphi_addline_to_memo("Hello world, this is end of my script");
      ?>

      regards and sorry for my english :-(

      Andrzej Kmicic

       
    • Wesley Milan

      Wesley Milan - 2009-02-01

      Andrzej, thanks for you help.  Your solution is fantastic, this will be very usefull, but I need this echo  in runtime to monitor error messages coming from the script.  Then I´m thinking in what happening in the browser when we run a long script.

      Any way, thank you.

       
    • Wesley Milan

      Wesley Milan - 2009-02-05

      I´m trying to run this code but PHP can´t find the function.  Any can help?

       

Log in to post a comment.