Jump to content

chaiwei

Members
  • Posts

    127
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

chaiwei's Achievements

Member

Member (2/5)

0

Reputation

  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. ya.. phpchamps is correct. you are missing 1 } }elseif($field == "Last_Name"){
  4. 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.
  5. Thank you Mchl. You really help me a lot.
  6. How about using PHP cli, is that possible to use php cli to communicate with webcam/smart card reader? Please advise.
  7. I also can reset the array using reset() in php. reset($testArray);
  8. 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
  9. Hi, My server mysql database used up to 800mb of memory usage. I have checked through "ps aux" command and restart the mysqld Is it possible because of the slow query? Please advice.
  10. 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++?
  11. 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 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]
  12. 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
  13. 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.
  14. 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.
  15. 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 the java VM is installed in client PC right? Or server also needed? Is that possible to install java in ubuntu server?
×
×
  • 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.