Jump to content

chaiwei

Members
  • Posts

    127
  • Joined

  • Last visited

Posts posted by chaiwei

  1. ok.. found out the reason,

     

    It seems like I need to share the file open resources between those function

    below is the working code.

    class curl2{
    
        private $curl_init; 
        private $CURLOPT_URL;
        private $fp;
    
        public function connect(){ 
           $this->curl_init = curl_init(); 
           return $this;
        }
    
        public function debug(){
    
           curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE);
    
           $this->fp = fopen("curl2.txt", "w");  
           curl_setopt($this->curl_init, CURLOPT_STDERR, $this->fp); 
    
           curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE);
    
           return $this;
        }
    
        public function setUrl($url = null){
           $this->CURLOPT_URL = $url;
           curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL);
           return $this;
    
        }
    
        public function execute(){
            
           $out = curl_exec($this->curl_init);
           curl_close($this->curl_init);
    
           return $out;
        }
    }
    
    $curl2 = new curl2;
    
    $result = $curl2->connect()
             ->setUrl("http://www.linuxformat.co.uk")
             ->debug()
             ->execute();
    print $result;

     

    just change the $fp to $this->fp

  2. 
    class curl2{
    
        private $curl_init; 
        private $CURLOPT_URL;
    
        public function connect(){ 
           $this->curl_init = curl_init(); 
        }
    
        public function debug(){
    
           curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE);
           $fp = fopen("curl2.txt", "w"); 
           curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); 
           curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE);
    
        }
    
        public function setUrl($url = null){
           $this->CURLOPT_URL = $url;
           curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL);
        }
    
        public function execute(){
    
           $out = curl_exec($this->curl_init);
           curl_close($this->curl_init);
    
           return $out;
        }
    }
    
    $curl2 = new curl2;
    $curl2->connect();
    $curl2->setUrl("http://www.linuxformat.co.uk");
    $curl2->debug();
    echo $curl2->execute();
    
    

     

    It display a blank page like attachment result1.jpg, but if I move the

    $fp = fopen("curl2.txt", "w"); 
    curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); 
    curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE);

    from function debug() and join it with function execute()

    like this:

      public function execute(){
           $fp = fopen("curl2.txt", "w"); 
           curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); 
           curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE);
    
           $out = curl_exec($this->curl_init);
           curl_close($this->curl_init);
    
           return $out;
        }

     

    it return me Linuxformat content ( expected result ) like result2.jpg

     

    below is the working code :

    class curl2{
    
        private $curl_init; 
        private $CURLOPT_URL;
    
        public function connect(){ 
           $this->curl_init = curl_init(); 
        }
    
        public function debug(){
    
           curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE);
          
    
        }
    
        public function setUrl($url = null){
           $this->CURLOPT_URL = $url;
           curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL);
        }
    
        public function execute(){
           $fp = fopen("curl2.txt", "w"); 
           curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); 
           curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE);
    
           $out = curl_exec($this->curl_init);
           curl_close($this->curl_init);
    
           return $out;
        }
    }
    
    $curl2 = new curl2;
    $curl2->connect();
    $curl2->setUrl("http://www.linuxformat.co.uk");
    $curl2->debug();
    echo $curl2->execute();
    

     

    Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec"

     

     

    [attachment deleted by admin]

  3. Hi,

     

    Let said I have 3 branch factory locate on 3 different country, china, singapore and malaysia.

    Each branch has its own local server, so when the time internet down, they still can access to the application.

     

    But how can I share the database so that when the customer from china came to singapore factory, and the singapore crm check his passport or identification and it shows that we already have his record in china?

     

    mysql replication? but if like this we got 3 master and 1 slave. is it possible?

    Please advise.

     

     

  4. I saw sample of Iterator code on php.net

     

    class MyIterator implements Iterator
    {
        private $var = array();
    
        public function __construct($array)
        {
            if (is_array($array)) {
                $this->var = $array;
            }
        }
    
    
        public function current() {
            $var = current($this->var);
            echo "current: $var<br />";
            return $var;
        }
    
        
        public function rewind() {
            echo "rewinding<br />";
            reset($this->var);
        }
    
        public function key() {
            $var = key($this->var);
            echo "key: $var<br />";
            return $var;
        }
    
        public function next() {
            $var = next($this->var);
            echo "next: $var<br />";
            return $var;
        }
    
        public function valid() {
            $var = $this->current() !== false;
            echo "valid: {$var}<br />";
            return $var;
        }
    }
    
    class MyCollection implements IteratorAggregate
    {
        private $items = array();
        private $count = 0;
    
        // Required definition of interface IteratorAggregate
        public function getIterator() {
            return new MyIterator($this->items);
        }
    
        public function add($value) {
            $this->items[$this->count++] = $value;
        }
    }
    
    $coll = new MyCollection();
    $coll->add('value 1');
    $coll->add('value 2');
    $coll->add('value 3');
    
    foreach ($coll as $key => $val) {
        echo "key/value: [$key -> $val]<br /><br />";
    }

     

    With another sample I create:

    $testArray = array('value 1', 'value 2', 'value 3');
    $first = 0;
    define("breakline", "<br />");
    echo '-------------------------------------------------'.breakline;
    foreach($testArray as $key => $value){
        if($first == 0){
            echo 'rewinding'.breakline;
            $first = 1;
        }
        echo 'current: '.$value.breakline;
        echo 'valid: ';
        echo ($value)?1:0;
        echo breakline;
        echo 'current: '.$value.breakline;
        echo 'key: '.$key.breakline;
        echo 'key/value: ['.$key.' -> '.$value.']'.breakline;
        echo breakline;
    }
    echo 'next: '.breakline;
    echo 'current: '.breakline;
    echo 'valid: '.breakline;

     

    I can not see the advantage of using Iterator.

     

    Please advices

     

     

  5. Hi,

     

    1. What is the use of iterator SPL  since we can use while loop, foreach and for loop?

        I can't find its useful usage for me. can you give me an example?

     

    2. Mysql is opensource?

        if I used it to create a system using php and mysql and sell it to others. Do I need to pay for that?

     

    3. Stored procedure is better?

        I have look in the sourcecode and I found that my friend was using stored procedure.

        As they told me stored procedure is save server memory for running millions of query.

        but the cons is they are hard to maintain. Is that true?

     

    4. My friends was using prostgre sql integrate with c language.

        he said that will be faster compare to just use php and mysql.

        Is that true? Is there any way to integrate mysql with c?

        or I can use php integrate with c. will it faster compare to

        postgresql with c?

     

    5. what is the best/stable free c/c++ compiler and can use with apache, php and mysql server?

        g++?

     

     

  6. C(++) is considered to be 'lower level' in relation to php

     

    What does it mean by "lower level in relation to php"?

    Sorry, I don't get you. Is it we can compile php script to c++ and run on server?

     

    But what is the purpose to convert PHP into c++? (is it call extending and embedding php to c)?

    after convert, it will harder to maintain from what I see.

     

     

    or the other way rounds,

    example like I write a c++ script and compile it become a php extension install on server.

    then I can use the c++ function in php script?

     

    Let said PHP GD library orginal is written using C++, and then

    I compile it become PHP extension and install it on server.

     

    -----------------------

     

    Every devices/hardware must have it's own driver, which is dll file right?

    so is that means the dll for the devices, is the API/key/library to provide a bridge between software and hardware?

     

    So let said I have a USB webcam, in order to use, I must install its own driver.

    Then if I want to create a software/client programs to control the webcam,

    example like, do a snapshot, or even like MSN, create a video conferencing.

    I must use C++ to include the dll file? in order for my script to talk with to devices.

     

     

    So as you said

    python, perl, that is it's closer tied with the operating system and sometimes even with hardware

     

    Like those scanner, web cam, microphone is it easier or better to develop using python instead of c++,

    or perl, java?

     

     

    Example I saw a smartcard reader script develop using c language.

    Have a look on the attachment.

     

    How do I know which file I need to include in order to communicate with the devices?

     

    winscard.h?

    scarderr.h?

    SCARD_E_NO_READERS_AVAILABLE?

     

     

     

    [attachment deleted by admin]

  7. Thank you.

    So you mean C++ can do the GUI by using win32 API?

    Is there any tutorials or website for me to refer that?

     

    So if I have created the cpp file, so I just need to compile it to exe file?

    and the exe file will automatic call the win32 API and generate the GUI?

     

    Is that got any editor for me to use in order to generate the GUI like drag and drop?

    Or I have to manually write my own coding?

     

    Is c++ more powerful compare to perl or python?

    I really got zero knowledge on that.

     

    and C++ can run on linux operating system?

     

    Again, thank you for your time and your great help

  8. Thanks for the great info, but did Visual C++ required license to develop?

    I plan to consider open source language since I have limited budget as a student.

     

    Btw, what is the advantage of using c++ over VB6 or VB.NET?

     

    Please advise.

    Thank you again for your time and great help.

     

  9. that would communicate over network with your PHP application.

    Let said, I build a VB application client programs, and it connect with

    mysql database on server. and then I create a php script on server

    for web based reports for admin to manage/view.

     

    Is this "communicate over network with your PHP application" like what you mean?

     

    I have only use PHP most of the time.

    Do you have any recommendation language for me to use to create the client programs?

     

    VB6, VB.Net, Python, C, C++, c#, perl, java?

     

    The client program must be GUI and is able to connect to other devices.

     

    Thank you for spending your time to help me. I very appreciate that.

     

  10. Thank you for your help,

    please allow me to have few more questions.

     

    So you means with php exec function, can I execute client's pc script language?

    or you mean I install the php server on the client PC?

     

    As per documentation on php-java, the requirement stated as below

    You need a Java VM installed on your machine to use this extension.

    the java VM is installed in client PC right?

     

    Or server also needed?

    Is that possible to install java in ubuntu server?

     

     

  11. Dear Phpfreaks,

     

    I need to develop a smartcard reader application in my college,

    but I doesn't aware of if PHP is able to do this kind of thing.

    I have a iris smart card reader, and the driver,

    but I don't how to use PHP to communicate with the devices.

     

    I have googling for almost 1 weeks, it seems like PHP is not cater for it.

    I have search for PHP-GTK, roadsand, but I don't know how to do it.

    Additionally I have found a script using C language is able to get the data.

    It generate a few files.

    http://forum.lowyat.net/topic/355950#19

     

    So is there got any other workarounds to solve it?

    Maybe used PHP to execute the C script on client PC.

    and upload the file to server and server convert it?

     

    Please advise and your comments or idea is very much appreciated.

    thank you.

     

  12. Hi,

     

    I try to run a sync between two database.

    1 is localhost in my pc and another 1 is on webserver (remote)

     

    Okay, Let say I have 500,000 rows in a table, and I also just want to sync this table only.

    I use a SELECT * FROM table, and then use while loop and generate a sql

     

    Insert into xx VALUES ( xxx ), (xxx) ,(xxx) 
    

     

    after that, I use ajax call to a script, pass the sql through ajax post method,

    and use mysql_query to insert it into my pc.

     

    However I keep getting exhausted memory,

     

             function query($sql) {
                   
                          $resource = mysql_query($sql, $this->dbconnection);
    
                          if ($resource) {
                            if (is_resource($resource)) {
                              $i = 0;
                            
                              $data = array();
                          
                              while ($result = mysql_fetch_assoc($resource)) {
                                $data[$i] = $result;
                            
                                $i++;
                              }
                              
                              mysql_free_result($resource);
                              
                              $query = new stdClass();
                              $query->row = isset($data[0]) ? $data[0] : array();
                              $query->rows = $data;
                              $query->num_rows = $i;
                              
                              unset($data);
    
                              return $query;    
                              } else {
                              return TRUE;
                            }
                          } else {
                                exit('Error: ' . mysql_error($this->dbconnection) . '<br />Error No: ' . mysql_errno($this->dbconnection) . '<br />' . $sql);
                         }
                  } 

     

    I am not sure is this causing the exhausted memory issues.

     

    is it this problem?

    $query = new stdClass();

     

    I wonder how bigdump handle the ajax call and even it import a million row of record in the table

    it wouldn't have an memory issues.

     

     

  13. I stuck at here. 

     

          $sql = 'SHOW TABLES';
                 $result = $remote->query( $sql );
                 foreach($result->rows as $value){
                     $sql = 'SELECT * FROM '. $value['Tables_in_commerce'].'<br />';
                     $local->query('Create TABLE '. $value['Tables_in_commerce']);
               
    
                 }

     

    Create table xxx xxx

     

    How I gonna get the field name, field type, primary key, collaction

    and put in the create table syntax?

     

  14. oops, sorry..

     

    I have a live application and database in SERVER A,

    then my boss want to use the application even offline (without internet),

    So I need to install xampp in his computer,

    then I need to create a button that let him press once

    and the live database will pump inside the xampp database.

     

    Normally I can use phpmyadmin to export into a sql file,

    and then use pendrive and copy to my boss pc, and import again.

    but he don't want like this, what he want is create a button and once press,

    the application will look up the live database, and insert in his own pc database,

    so his pc will have the latest updated data.

     

    I only can come with the idea is create a script and with two connection,

    $conn = mysql_connect('192.168.2.4' , xxx,xxx)
    $conn1 = mysql_connect('192.168.2.5', xxx, xxx)
    
    SELECT * FROM -> using $conn
    while(xxx xxx){
    
      INSERT INTO -> using $conn1
    
    }
    

     

    but if the database is large, then the process will take very long time to complete.

     

    right?

     

    So I wonder whether the above example will slower compare to use phpmyadmin to export and then import again?

     

    if that any other ways to complete this?

     

     

  15. Hi,

     

    I want to have mysql sync between two same application different host using same databases.

    So I need to create two connection in php?

    Ok , example, server A and server B

     

    So if I want to sync FROM  A  to  B 

    So I drop all the table in B first,

    then create the new table in B

    then select * table from server A using php and INSERT INTO server B ?

     

    or I create a sql file from server A after that using import into server B is more efficient?

     

     

     

  16. I have a table like this:

    job_id, resume_id, status, datestamp

    3965 78826 accepted 2009-12-11 16:34:58
    3965 79307 accepted 2009-12-17 11:04:36
    3965 78826 can-rejected 2010-01-11 11:09:13
    3965 56341 suitable 2009-12-03 11:25:58
    3965 78826 suitable 2009-12-11 16:34:51
    3965 79307 suitable 2009-12-17 11:04:33

    I want it become like this

     

    job_id, resume_id, status, datestamp

    3965 79307 accepted 2009-12-17 11:04:36
    3965 78826 can-rejected 2010-01-11 11:09:13
    3965 56341 suitable 2009-12-03 11:25:58

     

    I can use subquery to do this:

     

    SELECT * 
    FROM resume_application_status rjs, 
       (SELECT max(datestamp) as datestamp FROM resume_application_status rjs 
        GROUP BY job_id,resume_id ) rjs2 
    WHERE rjs.datestamp = rjs2.datestamp 
    GROUP BY job_id,resume_id

     

    but this is subquery, are there any option to do this without using subquery?

    Because I can't create view using subquery

     

  17. <div id="maincontent">
       <div class="innertube">
          
           <div style="width:50px;margin:0 auto;background-color:red;">This is center div</div>
    
       </div>
    </div>

     

    The trick is use margin:0 auto;

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.