[PHP] Increasing maximum file descriptors (OS X Lion 10.7, PHP 5.3.8 via Macports)
I have a working socket server in PHP that I wish to improve (allow for more socket connections). I am running into a limit I can't crack, related to the max number of incoming socket connections. Using Macports for package management... I've recompiled PHP with the --enable-fd-setsize=2048 in the port file) … but I still get the following PHP warning once my socket server tries to accept more than 1024 clients (800, 900 are okay): PHP Warning: socket_select(): You MUST recompile PHP with a larger value of FD_SETSIZE. It is set to 2048, but you have descriptors numbered at least as high as 1027. --enable-fd-setsize=2048 is recommended, but you may want to set it to equal the maximum number of open files supported by your system, Weird right? Shows I have it set in PHP, so maybe it's a resource limit? But having changed sysctl.conf, ulimit -a shows: core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited file size (blocks, -f) unlimited max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files (-n) 2048 pipe size(512 bytes, -p) 1 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 709 virtual memory (kbytes, -v) unlimited So I should be able to have up to 2048 files (sockets) open, but PHP still complains. What am I missing? Any ideas what I should try next? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
On 2009-12-15, at 11:55 PM, Richard Quadling wrote: Do you have a default stream context defined for the http stream? Nope. A _LONG_ time ago, when I was using a firewall with NTLM authentication (which PHP doesn't deal with), I had to route all my calls through a local proxy. This was the code I had ... ?php // Define the default, system-wide context. $r_default_context = stream_context_get_default( array( 'http' = array( // All HTTP requests are passed through the local NTLM proxy server on port 8080. 'proxy' = 'tcp://127.0.0.1:8080', 'request_fulluri' = True, ), ) ); // Though we said system wide, some extensions need a little coaxing. libxml_set_streams_context($r_default_context); Now, you may not see this in your code, but may be in a script which is loaded via auto_prepend_file. Wish it were, but my test code is bare bones. I would also suggest running something like WireShark at the same time as your script. See if there is ANY traffic over the wire. Do the cURL and file_get_contents() code generate identical requests? cURL -- both PHP and command-line -- fetches files and URLs (remote and local) w/o issues. file_get_contents() fetches files, but fails on all URLs (remote and local). This is why I believe the problem lies with the machine's configuration and not the Firewall. It's pretty confounding, isn't it? I'm not sure what to do at this point. ...Rene
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
On 2009-12-15, at 11:55 PM, Richard Quadling wrote: Do you have a default stream context defined for the http stream? Nope. A _LONG_ time ago, when I was using a firewall with NTLM authentication (which PHP doesn't deal with), I had to route all my calls through a local proxy. This was the code I had ... ?php // Define the default, system-wide context. $r_default_context = stream_context_get_default( array( 'http' = array( // All HTTP requests are passed through the local NTLM proxy server on port 8080. 'proxy' = 'tcp://127.0.0.1:8080', 'request_fulluri' = True, ), ) ); // Though we said system wide, some extensions need a little coaxing. libxml_set_streams_context($r_default_context); Now, you may not see this in your code, but may be in a script which is loaded via auto_prepend_file. Wish it were, but my test code is bare bones. I would also suggest running something like WireShark at the same time as your script. See if there is ANY traffic over the wire. Do the cURL and file_get_contents() code generate identical requests? cURL -- both PHP and command-line -- fetches files and URLs (remote and local) w/o issues. file_get_contents() fetches files, but fails on all URLs (remote and local). This is why I believe the problem lies with the machine's configuration and not the Firewall. It's pretty confounding, isn't it? I'm not sure what to do at this point. ...Rene
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
Well thanks for trying. For anyone reading this, who wants to be a hero and solve the impossible: 1. file_get_contents ($url) doesn't work -- (on remote URLs or local URLs) 2. file_get_contents ($file) works. 3. CURL works (on remote and local URLs). 4. as per php.ini, allow_url_fopen On Xserve - OS X Server 10.6.2 - PHP 5.3 (default) So... it's as if PHP is not respecting the allow_url_fopen direction in php.ini. If that directive were set to Off, everything would make sense (files load, urls don't (local or remote)). Anyone have anything to add? Anyone, anyone? Bueller? On 2009-12-14, at 10:05 PM, Gaurav Kumar wrote: Sorry buddy, I cant think of anything else which is going on wrong. 2009/12/14 René Fournier m...@renefournier.com PHP Version 5.3.0 Directive Local Value Master Value allow_call_time_pass_referenceOff Off allow_url_fopen On On 2009-12-14, at 12:26 AM, Gaurav Kumar wrote: What is the value for allow_url_fopen in your php.ini? It should be 1. 2009/12/13 René Fournier m...@renefournier.com CURL works (remote and local) file_get_contents() doesn't work (remote or local). On 2009-12-13, at 4:39 PM, Gaurav Kumar wrote: Ok Agreed. Lets do one last chance to ensure that your system is allowing external connections or connection to other systems in the network- Use Curl to get in the file contents. Check your PHP that Curl is enabled. Through phpinfo(); If the script output the google page then this means that there is nothing that is stopping you form getting in the content externally. ?php // $str = file_get_contents ('http://www.google.com'); // echo $str; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, http://www.google.co.in;); //http://www.google.com curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ? Thanks, Gaurav Kumar 2009/12/13 René Fournier m...@renefournier.com The thing is, the file_get_contents() fails the same way on local URLs -- that is, web sites hosted on the same machine. Or even using the machine's own IP address. On 2009-12-13, at 4:00 AM, Gaurav Kumar wrote: Hi Rene, The only thing which is a hurdle is that your system/computer is not allowing external connections. There seems to be nothing else wrong. I strongly suggest check your system firewall, any central server settings through which your system gets internet access, any antivirus s/w installed etc.. this can be the only reason. Something is stopping you to access external connection. Let me know when your problem is fixed. Also I tried the below code and it works fine- ?php $str = file_get_contents ('http://www.google.com'); echo $str; ? Thanks, Gaurav Kumar 2009/12/11 René Fournier m...@renefournier.com Hi Gaurav, On 2009-12-11, at 2:55 PM, Gaurav Kumar wrote: A very typical problem. Good you sent the error message. This problem can be caused due to one of the following- 1. I have faced similar problem due to local firewall settings. Don't think this is it, since (1) the firewall settings haven't changed, and (2) other machines on the same network can execute this same code and function (but they aren't running OS X Server 10.6. 2. Try some other domain; i.e. other than google com. Try some of the local area website with a particular page like www.somedomain.com/somefile.html I've tried many different external and local web sites, and they all fail. 3. Some times the remote host does not allow you to connect to get the file contents. (Also not the cause -- as explained above.) 4. # 3 can be either way round from both the ends a) you host server does not allow external connections b) Remote host does not allow anonymous connection. Thanks for the options. I don't think they apply in this case. If you have any other suggestions on what to do, I would welcome them. Gaurav Kumar blog.oswebstudio.com On Thu, Dec 10, 2009 at 9:01 PM, René Fournier m...@renefournier.com wrote: I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
On 2009-12-14, at 10:44 PM, Cafer Şimşek wrote: René Fournier m...@renefournier.com writes: 4. as per php.ini, allow_url_fopen On Look at from phpinfo() the settings is already On. Yes, I know. Which is why it's odd that the function fails on URLs. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
CURL works (remote and local) file_get_contents() doesn't work (remote or local). On 2009-12-13, at 4:39 PM, Gaurav Kumar wrote: Ok Agreed. Lets do one last chance to ensure that your system is allowing external connections or connection to other systems in the network- Use Curl to get in the file contents. Check your PHP that Curl is enabled. Through phpinfo(); If the script output the google page then this means that there is nothing that is stopping you form getting in the content externally. ?php // $str = file_get_contents ('http://www.google.com'); // echo $str; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, http://www.google.co.in;); //http://www.google.com curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ? Thanks, Gaurav Kumar 2009/12/13 René Fournier m...@renefournier.com The thing is, the file_get_contents() fails the same way on local URLs -- that is, web sites hosted on the same machine. Or even using the machine's own IP address. On 2009-12-13, at 4:00 AM, Gaurav Kumar wrote: Hi Rene, The only thing which is a hurdle is that your system/computer is not allowing external connections. There seems to be nothing else wrong. I strongly suggest check your system firewall, any central server settings through which your system gets internet access, any antivirus s/w installed etc.. this can be the only reason. Something is stopping you to access external connection. Let me know when your problem is fixed. Also I tried the below code and it works fine- ?php $str = file_get_contents ('http://www.google.com'); echo $str; ? Thanks, Gaurav Kumar 2009/12/11 René Fournier m...@renefournier.com Hi Gaurav, On 2009-12-11, at 2:55 PM, Gaurav Kumar wrote: A very typical problem. Good you sent the error message. This problem can be caused due to one of the following- 1. I have faced similar problem due to local firewall settings. Don't think this is it, since (1) the firewall settings haven't changed, and (2) other machines on the same network can execute this same code and function (but they aren't running OS X Server 10.6. 2. Try some other domain; i.e. other than google com. Try some of the local area website with a particular page like www.somedomain.com/somefile.html I've tried many different external and local web sites, and they all fail. 3. Some times the remote host does not allow you to connect to get the file contents. (Also not the cause -- as explained above.) 4. # 3 can be either way round from both the ends a) you host server does not allow external connections b) Remote host does not allow anonymous connection. Thanks for the options. I don't think they apply in this case. If you have any other suggestions on what to do, I would welcome them. Gaurav Kumar blog.oswebstudio.com On Thu, Dec 10, 2009 at 9:01 PM, René Fournier m...@renefournier.com wrote: I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen I've checked php.ini Right, must remember not to reply to stuff till I'm awake. :-D -- PHP General Mailing List (http
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
PHP Version 5.3.0 Directive Local Value Master Value allow_call_time_pass_reference Off Off allow_url_fopen On On 2009-12-14, at 12:26 AM, Gaurav Kumar wrote: What is the value for allow_url_fopen in your php.ini? It should be 1. 2009/12/13 René Fournier m...@renefournier.com CURL works (remote and local) file_get_contents() doesn't work (remote or local). On 2009-12-13, at 4:39 PM, Gaurav Kumar wrote: Ok Agreed. Lets do one last chance to ensure that your system is allowing external connections or connection to other systems in the network- Use Curl to get in the file contents. Check your PHP that Curl is enabled. Through phpinfo(); If the script output the google page then this means that there is nothing that is stopping you form getting in the content externally. ?php // $str = file_get_contents ('http://www.google.com'); // echo $str; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, http://www.google.co.in;); //http://www.google.com curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ? Thanks, Gaurav Kumar 2009/12/13 René Fournier m...@renefournier.com The thing is, the file_get_contents() fails the same way on local URLs -- that is, web sites hosted on the same machine. Or even using the machine's own IP address. On 2009-12-13, at 4:00 AM, Gaurav Kumar wrote: Hi Rene, The only thing which is a hurdle is that your system/computer is not allowing external connections. There seems to be nothing else wrong. I strongly suggest check your system firewall, any central server settings through which your system gets internet access, any antivirus s/w installed etc.. this can be the only reason. Something is stopping you to access external connection. Let me know when your problem is fixed. Also I tried the below code and it works fine- ?php $str = file_get_contents ('http://www.google.com'); echo $str; ? Thanks, Gaurav Kumar 2009/12/11 René Fournier m...@renefournier.com Hi Gaurav, On 2009-12-11, at 2:55 PM, Gaurav Kumar wrote: A very typical problem. Good you sent the error message. This problem can be caused due to one of the following- 1. I have faced similar problem due to local firewall settings. Don't think this is it, since (1) the firewall settings haven't changed, and (2) other machines on the same network can execute this same code and function (but they aren't running OS X Server 10.6. 2. Try some other domain; i.e. other than google com. Try some of the local area website with a particular page like www.somedomain.com/somefile.html I've tried many different external and local web sites, and they all fail. 3. Some times the remote host does not allow you to connect to get the file contents. (Also not the cause -- as explained above.) 4. # 3 can be either way round from both the ends a) you host server does not allow external connections b) Remote host does not allow anonymous connection. Thanks for the options. I don't think they apply in this case. If you have any other suggestions on what to do, I would welcome them. Gaurav Kumar blog.oswebstudio.com On Thu, Dec 10, 2009 at 9:01 PM, René Fournier m...@renefournier.com wrote: I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
The thing is, the file_get_contents() fails the same way on local URLs -- that is, web sites hosted on the same machine. Or even using the machine's own IP address. On 2009-12-13, at 4:00 AM, Gaurav Kumar wrote: Hi Rene, The only thing which is a hurdle is that your system/computer is not allowing external connections. There seems to be nothing else wrong. I strongly suggest check your system firewall, any central server settings through which your system gets internet access, any antivirus s/w installed etc.. this can be the only reason. Something is stopping you to access external connection. Let me know when your problem is fixed. Also I tried the below code and it works fine- ?php $str = file_get_contents ('http://www.google.com'); echo $str; ? Thanks, Gaurav Kumar 2009/12/11 René Fournier m...@renefournier.com Hi Gaurav, On 2009-12-11, at 2:55 PM, Gaurav Kumar wrote: A very typical problem. Good you sent the error message. This problem can be caused due to one of the following- 1. I have faced similar problem due to local firewall settings. Don't think this is it, since (1) the firewall settings haven't changed, and (2) other machines on the same network can execute this same code and function (but they aren't running OS X Server 10.6. 2. Try some other domain; i.e. other than google com. Try some of the local area website with a particular page like www.somedomain.com/somefile.html I've tried many different external and local web sites, and they all fail. 3. Some times the remote host does not allow you to connect to get the file contents. (Also not the cause -- as explained above.) 4. # 3 can be either way round from both the ends a) you host server does not allow external connections b) Remote host does not allow anonymous connection. Thanks for the options. I don't think they apply in this case. If you have any other suggestions on what to do, I would welcome them. Gaurav Kumar blog.oswebstudio.com On Thu, Dec 10, 2009 at 9:01 PM, René Fournier m...@renefournier.com wrote: I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen I've checked php.ini Right, must remember not to reply to stuff till I'm awake. :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- 2866791487_dbbbdddf9e.jpg惠 新宸 xinchen.hui | 商务搜索部 | (+8610)82602112-7974 | 2866349865_203e53a6c6.jpg:laruence Do you have ANY errors/warning/notices? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
Hi Gaurav, On 2009-12-11, at 2:55 PM, Gaurav Kumar wrote: A very typical problem. Good you sent the error message. This problem can be caused due to one of the following- 1. I have faced similar problem due to local firewall settings. Don't think this is it, since (1) the firewall settings haven't changed, and (2) other machines on the same network can execute this same code and function (but they aren't running OS X Server 10.6. 2. Try some other domain; i.e. other than google com. Try some of the local area website with a particular page like www.somedomain.com/somefile.html I've tried many different external and local web sites, and they all fail. 3. Some times the remote host does not allow you to connect to get the file contents. (Also not the cause -- as explained above.) 4. # 3 can be either way round from both the ends a) you host server does not allow external connections b) Remote host does not allow anonymous connection. Thanks for the options. I don't think they apply in this case. If you have any other suggestions on what to do, I would welcome them. Gaurav Kumar blog.oswebstudio.com On Thu, Dec 10, 2009 at 9:01 PM, René Fournier m...@renefournier.com wrote: I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen I've checked php.ini Right, must remember not to reply to stuff till I'm awake. :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- 2866791487_dbbbdddf9e.jpg惠 新宸 xinchen.hui | 商务搜索部 | (+8610)82602112-7974 | 2866349865_203e53a6c6.jpg:laruence Do you have ANY errors/warning/notices? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
I thought error_reporting would display them, but I guess php.ini had them suppressed. Anyway, with: ?php error_reporting(-1); ini_set('display_errors', 1); set_time_limit(0); var_dump (file_get_contents ('http://www.google.com')); ? I get: Warning: file_get_contents(http://www.google.com): failed to open stream: Operation now in progress in //.php on line 7 bool(false) Does that help with the diagnosis? On 2009-12-10, at 12:28 AM, Richard Quadling wrote: 2009/12/9 René Fournier m...@renefournier.com: It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen I've checked php.ini Right, must remember not to reply to stuff till I'm awake. :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- 2866791487_dbbbdddf9e.jpg惠 新宸 xinchen.hui | 商务搜索部 | (+8610)82602112-7974 | 2866349865_203e53a6c6.jpg:laruence Do you have ANY errors/warning/notices? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
[PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
No. And it doesn't matter if the url is local (localhost, host.domain.com) or remote. On 2009-12-09, at 10:30 PM, kranthi wrote: may be unrelated to your problem... but are you behind a proxy?
Re: [PHP] file_get_contents ($file) works -- file_get_contents ($url) returns false
It is, and I use curl elsewhere in the same script to fetch remote content. This exact same function works fine on my MacBook Pro (10.6 client, PHP 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3, On 2009-12-09, at 11:10 PM, laruence wrote: try wget http://www.google.com in your command line to see whether the network is reachable LinuxManMikeC wrote: On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC linuxmanmi...@gmail.com wrote: On Wed, Dec 9, 2009 at 6:45 AM, René Fournier m...@renefournier.com wrote: Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3. Any call of file_get_contents() on a local file works fine -- the file is read and returned. But any call of file_get_contents on a url -- any url, local or remote -- always returns false. var_dump (file_get_contents ('http://www.google.com/')); bool(false) I've checked php.ini, and the obvious seems okay: allow_url_fopen = On = On Any ideas? ...Rene http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen I've checked php.ini Right, must remember not to reply to stuff till I'm awake. :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- 2866791487_dbbbdddf9e.jpg惠 新宸 xinchen.hui | 商务搜索部 | (+8610)82602112-7974 | 2866349865_203e53a6c6.jpg:laruence
[PHP] What was the unix timestamp of last week, Monday 12:00 am?
I'm trying to write a [simple] function, such that: function earlier_unix_timestamp () { $now = mktime(); [...] return $then; // e.g., 1238983107 } Anyone have something already made? There seem to be many ways to skin this cat, with date() arithmetic, etc., but the exceptions (Jan 1, first day of the month, etc.) are driving me crazy. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
On 11-Dec-07, at 2:13 PM, Per Jessen wrote: René Fournier wrote: However, the number of socket clients connecting in the past 3-4 months has steadily increased, and this seems to have exposed (if not created) a strange performance issue with PHP 5.2.4, MySQL 5.0.45 and/or Mac OS X Server 10.4.11. (I say and/or because I am unsure where the problem's cause really lies.) Basically, after the script has been running for a day or so (processing essentially the amount data that used to take two weeks), the CPU usage of the machine goes from 30% (normal) to 80-90%. Have you tried stracing it to see what's really happening when the load goes that high? Good advice, since I think there's nothing left for me to do but inspect the MySQL process. Incidentally, I've made some changes to the script a week ago, which has seemed to improve the situation somewhat. Now, the script has run for nearly 7 days without interruption or high CPU load. Problem solved? Again this morning, I noticed CPU went up to 90% and is staying there. (Previously, this would happen after 1-2 days.) The number of distinct MySQL connections remains low, since the script (which runs in a loop, with a sleep(1) and a timeout on the stream_socket_select()), only creates one MySQL connection in the beginning. All MySQL queries run through that. The script has run for 6-7 days, during which time it's executed 2.7 million queries (mostly SELECTs) and created 105,198 external, short- lived child processes (each lasts about a second or two, then closes after mysql_close())--I don't think this is an issue. Memory usage seems okay. By the end of 7 days, the script's memory usage has peaked at 4MB (out of 16MB max). Typically it's around 3MB. MySQL memory usage doesn't seem to be a constraint. I'm using my- huge.cnf, and the nature of the queries is fairly regular. I would say that the database structure is not an issue (though I could be wrong!)--everything is pretty well normalized and indexed. I'm logging slow queries, non-indexed SELECTs, etc. I'm really not sure what to try next. ps -aux shows MySQL as hogging the CPU, not PHP or Terminal: PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE 342 mysqld 83.3% 16:13:19 33 125 139 435M 4.75M 439M 539M 385 Terminal 4.7% 5:36:35 22 184 251 20.1M 33.5M 28.8M+ 256M 1190 php 4.3% 3:13:33 1 15 148 6.51M 8.15M 12.1M 89.0M 0 kernel_tas 1.3% 2:02:40 47 2 619 5.00M- 0B 219M- 1.26G- It's really strange and strangely consistent. The script will run for a few million cycles, whereupon MySQL suddenly uses 50% more CPU. But for what? I'm looking at tutorials on ktrace and kdump to see what I can learn from MySQL. I wonder if I would have this problem under Linux... ...Rene
Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
That makes sense, but I'm not sure I really want to do this, since it's fairly important that Listener continue listening without interruption. I also don't think it's probably necessary, since from what I read, I'm not really pushing the envelope in terms of real load. Right now, I might have max ~250 clients connected, each sending 5-20 kb / day of data. It's not much data, nor many concurrent connections. If Jim's Listener handles 80-85k connections per day, then mine should be able to do 250 concurrently easily, and 2000 cumulative per day without a hitch. Did I mention, I'm on Mac OS X Server 10.4.11? Shouldn't matter, but anyway. On 10-Dec-07, at 5:48 PM, Jochem Maas wrote: Jim Lucas wrote: Tom Rogers wrote: Hi, ... Also, make sure you are not using an array that you are not re- initializing through each iteration of the loop. If the array keeps getting bigger, PHP might $*% on itself. Always re-initialize arrays to clean them up. even then he may still have creeping memory ... in which it might be possible to have a mother process that spawns and watchs a child process .. the child process is the actual deamon, the child could then keep a track of it's own memory usage and then kill itself when it gets too big ... the mother in turn would automatically spawn a new child deamon process upon seeing it's child has committed suicide. does that make sense? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Bug in stream_socket_server()?
If you want a high speed socket server, use the low-level sockets instead (socket_create/bind/listen). The stream_socket_server version appears to have internal fixed 8k buffers that will overflow if you don't keep up by reading. This is a serious problem if you an application that reads the socket for messages and then, say, saves the result in a database. The delay while it is busy processing means you can't read the data in time unless you get involved in muti-threading. With the the low-level functions, the OS quietly buffers TCP/IP packets so there is no problem (tested on Windows XP Professional). ( http://php.oregonstate.edu/manual/en/function.stream-socket- server.php#67837 ) Has anyone confirmed this? I am doing tests with a stripped-down multi-client socket server, wonder if this issue is causing some of the problems I've seen. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Pushing the limits of stream_socket_server() and stream_select()
Just curious what people found the limits to be with stream_socket_server(), in terms of maximum concurrent connections, packet sizes, etc. I'm am presently stress-testing a multi-client socket server and am finding I can sometimes break it with as few as 100 concurrent connections, and always break it with [precisely] 252 connections--with a variety of errors getting thrown: Client-side (100 connections, sometimes): PHP Warning: stream_socket_client(): unable to connect to tcp:// 192.168.0.41: (Operation timed out) in /Tuning/client.php on line 3 PHP Notice: fwrite(): send of 68 bytes failed with errno=32 Broken pipe in /Tuning/client.php on line 14 Server-side error ( 252+ connections, every time): PHP Warning: stream_select(): supplied argument is not a valid stream resource in /Tuning/server.php on line 15 Interestingly, the above server-side error only occurs when 252 clients are connected. At 251, it's okay. At 252, it generates the above PHP Warning. (Which really is strange. Anyone have any ideas?) If anyone is interested, I will post the sample code I'm using, in case--perish the thought--the problem is self-inflicted. :-) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Pushing the limits of stream_socket_server() and stream_select()
On 11-Dec-07, at 4:32 PM, René Fournier wrote: Just curious what people found the limits to be with stream_socket_server(), in terms of maximum concurrent connections, packet sizes, etc. I'm am presently stress-testing a multi-client socket server and am finding I can sometimes break it with as few as 100 concurrent connections, and always break it with [precisely] 252 connections--with a variety of errors getting thrown: Client-side (100 connections, sometimes): PHP Warning: stream_socket_client(): unable to connect to tcp:// 192.168.0.41: (Operation timed out) in /Tuning/client.php on line 3 PHP Notice: fwrite(): send of 68 bytes failed with errno=32 Broken pipe in /Tuning/client.php on line 14 Server-side error ( 252+ connections, every time): PHP Warning: stream_select(): supplied argument is not a valid stream resource in /Tuning/server.php on line 15 Interestingly, this 251 connection limit does not appear to be obviously system-related (I am running Mac OS X 10.4.11). I can run two instances of server.php and have each client.php spawn 175 connections (350 total concurrent to the machine), with no problem. Interestingly, the above server-side error only occurs when 252 clients are connected. At 251, it's okay. At 252, it generates the above PHP Warning. (Which really is strange. Anyone have any ideas?) If anyone is interested, I will post the sample code I'm using, in case--perish the thought--the problem is self-inflicted. :-) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Mac OS X Server limits... was [PHP] Pushing the limits of stream_socket_server() and stream_select()
OK, having done more digging, this bizarre 251-255 connections per socket limit seems to be an OS X thing. (Linux people, any comments?) At least that's I've read: http://www.macgeekery.com/tips/ configuration/mac_os_x_network_tuning_guide_revisited#comment-1433 So... Do any Mac OS X gurus out there know how to increase OS X Server's (10.4.11) maximum connections per socket value? There seems to no such setting in sysctl or ulimit. Any ideas? Anyone? Anyone? ...Rene On 11-Dec-07, at 4:55 PM, René Fournier wrote: On 11-Dec-07, at 4:32 PM, René Fournier wrote: Just curious what people found the limits to be with stream_socket_server(), in terms of maximum concurrent connections, packet sizes, etc. I'm am presently stress-testing a multi-client socket server and am finding I can sometimes break it with as few as 100 concurrent connections, and always break it with [precisely] 252 connections--with a variety of errors getting thrown: Client-side (100 connections, sometimes): PHP Warning: stream_socket_client(): unable to connect to tcp:// 192.168.0.41: (Operation timed out) in /Tuning/client.php on line 3 PHP Notice: fwrite(): send of 68 bytes failed with errno=32 Broken pipe in /Tuning/client.php on line 14 Server-side error ( 252+ connections, every time): PHP Warning: stream_select(): supplied argument is not a valid stream resource in /Tuning/server.php on line 15 Interestingly, this 251 connection limit does not appear to be obviously system-related (I am running Mac OS X 10.4.11). I can run two instances of server.php and have each client.php spawn 175 connections (350 total concurrent to the machine), with no problem. Interestingly, the above server-side error only occurs when 252 clients are connected. At 251, it's okay. At 252, it generates the above PHP Warning. (Which really is strange. Anyone have any ideas?) If anyone is interested, I will post the sample code I'm using, in case--perish the thought--the problem is self-inflicted. :-) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
Hello, I have a command-line PHP script--called Listener--that is designed to run indefinitely with a predictable CPU usage and memory footprint. In a nutshell, it's a multi-client socket server that waits for incoming connections, processes incoming data, stores results in a MySQL database, and basically gets on with its life. And it works. No errors or serious problems to speak of. And I've been running it for a couple years on an Xserve dual-G5 2GHz w/ OS X Server 10.4.11). Six months ago, the program would run for days, even a couple weeks, without a hitch. The only reason I would stop the script is for some other purpose, like a software update. However, the number of socket clients connecting in the past 3-4 months has steadily increased, and this seems to have exposed (if not created) a strange performance issue with PHP 5.2.4, MySQL 5.0.45 and/or Mac OS X Server 10.4.11. (I say and/or because I am unsure where the problem's cause really lies.) Basically, after the script has been running for a day or so (processing essentially the amount data that used to take two weeks), the CPU usage of the machine goes from 30% (normal) to 80-90%. This appears to be irrespective of the number of clients connected to the server at the time, but rather the amount of time the script has been running (and therefore cumulative cycles it's operated, data processed, MySQL queries executed, etc.). And the CPU usage stays high, even when the actual load (number of clients) decreases. At this time, if I run top, I get the following info: 22512 mysqld 91.6% 8:22:12 31 106 125 305M+ 3.20M 260M 475M 17104 php 7.2% 81:14.01 115 145 5.08M 7.80M 10.9M- 87.5M 22537 Terminal 6.6% 2:59:59 22 176 240 12.3M 21.2M 18.3M- 236M [...] At first I thought, okay, it's MySQL's fault. Maybe a lot of slow- running queries. But the slow query log is pretty clean. So maybe it's a combination of Mac OS X and MySQL and PHP? I Googled for a similar problem, and finally ran across this article: http://www.shawnhogan.com/2005/10/mysql-problems-on-mac-os-x-server.html ...where the author describes a very similar CPU usage pattern. I tried his suggested fixes and they seemed to have helped a little (or maybe it's my wishful thinking--hard to tell), since the high CPU load issue doesn't appear to happen as soon... But it still happens. Anyway, I'm really stumped as to what to do next, where to look, etc. If I stop the script, and restart it (but not the MySQL itself), CPU usage goes back to normal--for about a day or two. The only thing I thought might be connected is how many short-lived PHP child processes Listener creates--around 20-30,000 per day. Sounds higher, but on average it's just one every 2-3 seconds. Anyway, although the number of child processes isn't concurrent, would there be a problem with the number of historical child processes in view of ulimits or kern.maxfilesperproc? Anyway suggestions, tips, or links are much appreciated. Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
Hi Jim, I have a server that listens like yours does. I get 80k - 85k connections a day to it. When I first started it, I was only getting about 3k of connections aday. Then I upped the listening pattern and it tanked. I noticed that all my mail/web/db connections just sat there. When I investigated, I found that the number of connections to the server was being overloaded. So I increased the kern.maxfilesperproc setting to 32000. All the problems went away. I have about have the horse power you do, running OpenBSD 4.1, and it runs great now as my listener / web / ftp / mail / named / database / spam filter / etc... One question about the listener program, does it maintain a connection to the DB or does it open/close a connection upon each socket connection? If it does the latter, you might look into using a constant connection rather then opening/closing on a per connection basis. Thanks for the reply. (Not many people seem to be doing what I'm doing in the way I'm doing it... so I really appreciate the feedback.) I don't think the kern.maxfilesperproc setting is a problem. I'm currently set to 102400 per Shawn Hogan's advice. And my Listener program only receives ~1000 connections per day. However, each connection involves multiple MySQL queries, often as many as 50 or so per connection each day. So perhaps your second observation applies. MySQL is showing ~ 1,500 connections per hour. And I'm using mysql_connect() in Listener. I will see if using mysql_pconnect(), and reducing the number of connections helps. My.cnf's max connections, presently at 100, may have been too low in view using mysql_connect(). If mysql_pconnect() doesn't improve things, maybe I should bump up max_connections to 500? ..Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
On 10-Dec-07, at 4:42 PM, Tom Rogers wrote: Put a usleep(1000) in the listen while() loop and give the cpu a break. Good advice, but I've already been doing that. The thing is, when the script first starts up, the CPU rarely exceeds 30%, even when many clients (200+) are simultaneously connected and sending data. When a few clients are connected, CPU is typically below 10%. Again, it's only after 24-48 hours that, all of a sudden, CPU usage increases by 40-50%. And it stays high until I stop the script and restart it. One question I have though is, is there actually any benefit to using mysql_pconnect(), since the script simply loops? My understanding is that pconnect only benefits if a script would otherwise be using mysql_connect repeatedly--and this script doesn't, since it calls mysql_[p]connect() just once, in the start tof execution. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
On 10-Dec-07, at 5:20 PM, Jim Lucas wrote: Tom Rogers wrote: Hi, Tuesday, December 11, 2007, 6:42:18 AM, you wrote: RF Hello, Put a usleep(1000) in the listen while() loop and give the cpu a break. This makes me think about asking if you have to short of a timeout on your receiving connection? One second on stream_socket_server(), with a 900 second timeout stream_socket_accept(). What are you using to setup your connection? fsockopen() or stream_socket_server() ? here is a snippet of what I have [...] Thanks for sharing your code. Seems pretty similar to mine at first glance. I don't have a timeout set on the *_recvfrom() call. I just wait until the next connection comes in. You don't need to use mysql_pconnect(), especially if you are using, what in essence is, a daemon. Yeah, after thinking about it, that's what I figured. Thanks for confirming though. Just don't open and close the connection constantly, leave it open. Yes, I just open it once at the top of the script. And that's it. Also, make sure you are not using an array that you are not re- initializing through each iteration of the loop. If the array keeps getting bigger, PHP might $*% on itself. Always re-initialize arrays to clean them up. Hope some of this helps! All good advice. I will check my arrays, although I don't think this is a problem since I monitor the scripts memory usage with memory_get_usage() and memory_get_peak_usage(), and it never tops 3MB (max allocated is 16MB). There are a few little parts to the daemon. One thing I'm doing that could be problematic is running an include (); on a couple files each time a socket has new data (this allows me to adjust the processing logic on the fly without having to start the script and wait for clients to reconnect)--but I can see this being expensive in terms of performance and resources. Actually, I wonder if THAT is not what's starving the script of resources over time-- each fread() involves several includes(); I'll have to look into that... FWIW, here's the stripped-down skeleton of the server: As always, constructive criticism is very welcome. ?php $socket = stream_socket_server(tcp://127.0.0.1:9876, $errno, $errstr); if ($socket) { $master[] = $socket; $read = $master; $write = $master; while (1) { $read = $master; $write = $master; $mod_fd = stream_select($read, $_w = NULL, $_e = NULL, 1); if ($mod_fd === FALSE) { break; } for ($i = 0; $i $mod_fd; ++$i) { if ($read[$i] === $socket) {// NEW SOCKET $conn = stream_socket_accept($socket, 900); $master[] = $conn; $key_num = array_search($conn, $master, TRUE); } else { $sock_data = fread($read[$i], 32768); if (strlen($sock_data) === 0) { // CONNECTION GONE $key_to_del = array_search($read[$i], $master, TRUE); fclose($read[$i]); unset($master[$key_to_del]); } elseif ($sock_data === FALSE) { // CONNECTION BROKEN $key_to_del = array_search($read[$i], $master, TRUE); fclose($read[$i]); unset($master[$key_to_del]); } else { // READ INCOMING DATA // include (somefiles); // include (somefiles); // include (somefiles); // [ ... ] } } } } } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multi-threaded port listener
Anyone find any good tutorials, code samples, etc. on such a thing? Basically, I want to write server (in PHP) that listeners on a particular port, and spins off a thread/process (essentially, execute a separate script) for each incoming connection. There won't be a lot of data to process, but there will be many simultaneous connections— upwards of 1000s of connections (each spun off as seperate threads). ...Rene
[PHP] Possible?
Simple problem: Many client apps need to send data to a server. By default each client will open a persistent TCP socket connection to a common IP address:port (10.10.10.10:1234) and write to it (which the server will save/log, etc.). My question is, what should be ready to listen at the IP:port? I was thinking of writing a PHP command-line socket server that listens at that port. But there will be a potentially huge number of clients connecting simultaneously (1000s), not transmitting a lot of data per se, but a lot of connections... Anyway, instead I thought writing a simple PHP script—say, listener.php—that gets executed by the web server and enters a socket_read loop until the client terminates the connection (set_time_limit(0)). Does this sound like a good way to do it? This way, Apache handles all the connections, and PHP is instantiated each time, but without having to fork processes, etc, and without having to do PHP CLI. Anyway, I've started looking at this, but I'm not quite sure if it's even possible. I mean, can something send a request to Apache, and continue to write data along that TCP socket? Normally, HTTP requests include GET or POST for such data, but this is not a a web browser that's opening the connection. Hope I'm somewhat clear. Just struggling through some options here Anyway, thanks in advance for any suggestions. ...Rene
Re: [PHP] Possible?
Anyway, I've started looking at this, but I'm not quite sure if it's even possible. I mean, can something send a request to Apache, and continue to write data along that TCP socket? Normally, HTTP requests include GET or POST for such data, but this is not a a web browser that's opening the connection. Hope I'm somewhat clear. Just struggling through some options here Anyway, thanks in advance for any suggestions. ...Rene each client will open a persistent TCP socket connection to a common IP address:port (10.10.10.10:1234) (If you want simultaneous connections, each TCP connection will be to a different port.) Well, not if the client (actually, it's a pre-programmed physical device) is set to always open a socket connection to 10.10.10.10:1234... right? But rather than write a client and a server application from scratch, why not just use HTTP POSTs? I'm not writing the client, I just need to make a server that can accept numerous simultaneous incoming socket connections, and maintain them. Maybe stream_select() as someone suggested? I suppose my question would be, can a single PHP socket server script, executed from the command-line, maintain 1000s of concurrent connections (there is not a lot of data incoming, btw)? ...Rene
[PHP] Accessing data posted from a different URL
I have a script that periodically sends an email that includes form post to a script, which is meant to do something with the posted data. My problem is that apparently some PHP security measure is not permitting the externally posted data to be access via $_POST. I assume this is due to cross-site scripting issues, but in this case, I want to do just that. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing data posted from a different URL
Hmm, perhaps I didn't explain clearly. To put it another: 1. A script sends an email to a user with sign-in details. 2. The user clicks a [submit] button in the email message called Quick Sign In 3. A web browsers opens to http://www.website.com/signin.php (from the form method=post action=http://www.website.com/sign.php; in the email) 4. Signin.php looks for $_POST[signindetails] and auto-fills the form. Except the form post is not posting signindetails... On 20-Mar-06, at 2:57 PM, Jay Blanchard wrote: [snip] I have a script that periodically sends an email that includes form post to a script, which is meant to do something with the posted data. My problem is that apparently some PHP security measure is not permitting the externally posted data to be access via $_POST. I assume this is due to cross-site scripting issues, but in this case, I want to do just that. Any ideas? [/snip] http://www.php.net/curl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing data posted from a different URL
On 20-Mar-06, at 3:05 PM, Jay Blanchard wrote: [snip] Hmm, perhaps I didn't explain clearly. To put it another: 1. A script sends an email to a user with sign-in details. 2. The user clicks a [submit] button in the email message called Quick Sign In 3. A web browsers opens to http://www.website.com/signin.php (from the form method=post action=http://www.website.com/sign.php; in the email) 4. Signin.php looks for $_POST[signindetails] and auto-fills the form. Except the form post is not posting signindetails... [/snip] Have you tried print_r($_POST) ? Yes. And to answer a few other questions: The script, the email, the server—everything is on the same computer, running on top of the same Apache/PHP installation (v 4.3.11). The form is essentially: form method=POST target=SI action=http:// www.website.cominput type=hidden name=signindetails value=serialized and htmlentitized array values...input type=submit name=submit value=Fill/form I've narrowed it down a little farther: 1. If I copy the form from the email into the destination php page (ProcessSignin.php), and click Submit, it works—I get can see the $_POST[signindetails] 2. If I copy the form from the email into the original php page (MakeandSendSignin.php), and click Submit (with action=ProcessSignIn.php), it works—I can see the $_POST [signindetails] 3. ONLY if I click the Submit FROM the email—email client Mac OS X Mail.app or Outlook Excell—does it fail. The destination php page (ProcessSignin.php) appears, but print_r($_POST) reveals no $_POST [signindetails]. So, it appears that the email clients are stripping the POST data on Submit. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Accessing data posted from a different URL
On 20-Mar-06, at 4:40 PM, Richard Lynch wrote: On Mon, March 20, 2006 5:04 pm, René Fournier wrote: form method=POST target=SI action=http:// www.website.cominput type=hidden name=signindetails value=serialized and htmlentitized array values...input What does this value actually look like? How long is it? Is mail wrapping it to 72 characters with a newline, thereby breaking the data up? Though you would still get some POST data, just not what you thought... Actually, neither the form, nor the data seems to matter. I've copied in simple forms from elsewhere, and the only determining factor so far is: If the form is submitted from a web browser, the POSTed data IS available/visible (print_r) in the new web page. If the form--that is, any form--is submitted from an email client (any email client), the POSTed data IS NOT available/visible in the new web page. So... I can think of three explanations: 1. The email client (Mail or Outlook Express) is stripping the POST data on Submit. 2. The web browser (Safari, Firefox) is stripping incoming POST data if it's coming from outside the application. 3. PHP somehow knows if the form data is being POSTed from inside the web browser or not (and fails on the latter). Weird. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPMailer inserting unwanted spaces
Actually, I can send the example messages but here is another description of the same problem. (So PHPMailer is inserting line breaks, not spaces—or something is...) http://sourceforge.net/tracker/index.php? func=detailaid=1267539group_id=26031atid=385708 On 30-Dec-05, at 5:37 AM, Lam Cheuk Hin wrote: Can You Write The Strings/Text? On 12/30/05, René Fournier [EMAIL PROTECTED] wrote: Has anyone encountered this? I am composing an HTML email with PHPMailer, and for some reason PHPMailer is inserted spaces periodically, which breaks the formatting. I've looked through the docs, but can only find a setting for Word Wrap (which is set to 0). ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- lch2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPMailer inserting unwanted spaces
Has anyone encountered this? I am composing an HTML email with PHPMailer, and for some reason PHPMailer is inserted spaces periodically, which breaks the formatting. I've looked through the docs, but can only find a setting for Word Wrap (which is set to 0). ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] array_search() with preg_match?
I need to search an array for a string, with a twist. E.g.: $array = array(0 = 'this sky is blue', 1 = 'pencils are orange', 2 = 'I like green apples', 3 = 'strawberries are red'); $key = array_search('green', $array); With the above code, nothing will be returned, but I would like it to return 2 for the key containing green. Any suggestions? ...René -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Got a makestringsafe_for_filename() function?
I imagine some of you have written a nice little function for taking an arbitrary user-input string, and sanitizing and cleaning it for us as a UNIX (Mac OSX) filename... Would you mind sharing it? Thanks. René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Can this code go faster?
I've looked in the docs and don't see anything for this per se... I need to convert a binary number of arbitrary length to a signed integer. This is how I'm doing it now: CODE function bin2int ($bin) { if (substr($bin,0,1) == 1) { $val = 0 - bindec(substr($bin,1)); // NEGATIVE } else { $val = bindec(substr($bin,1)); // POSITIVE } } echo bin2int(1101).'br /'; echo bin2int(10001101); OUTPUT 13 -13 As you can see, if the most-significant bit is 1, then the rest of the value is negative. If the first bit is 0, then the rest is positive. Is there a better, faster (execution-wise) way of doing this? Maybe a more built-in function of PHP I missed? It's something that my script will be doing thousands of times, so I am concerned about speed. Thanks! ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Create MDB File
Coincidentally, I also need a way to read a table from MySQL and write it out to an .MDB file on-the-fly (from within a PHP script). The CSV export idea isn't an option in this case. Has anyone found a way to create an MDB file (with a single table) from PHP? ...Rene On 28-Mar-05, at 7:18 PM, Rory Browne wrote: MDB suggests Access, so why not simply create a CSV, or some other generic format file from your MySQL, and import it into access, using COM/OLE, and save it as an MDB file. On Mon, 28 Mar 2005 22:14:07 +0100, Shaun [EMAIL PROTECTED] wrote: Thanks for your reply, but this only works on Windows. I need a program that will create an MDB file on the fly from a query on the MySQL database... Johannes Findeisen [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sorry, i forgot that link: http://www.convert-in.com/sql2acc.htm On Monday 28 March 2005 22:46, Johannes Findeisen wrote: Hello, i had the same problem some years ago. At this time i have set up all tables in Access and wrote a script which reads from MySQL and inserts into the MDB file via the ODBC connector. This works but is much work when your database is very big. 2 Years ago i had the same problem but it must go as fast as possible so i decided to buy a converteer since i didn't find anything free. They are working very good. I don't know where i have buyed them but i think there is only one company which delivers this software. Regards Johannes On Monday 28 March 2005 22:08, Shaun wrote: Hi, Does anyone know if its possible to create an MDB file from a Mysql database using a PHP script, I have only managed to find Access to Mysql conversion programs so far... Thanks for your help -- # Johannes Findeisen -- # Johannes Findeisen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String format best practice
I need to output a Hex value, e.g.: 686E8AF8 In the following format: 68 6E 8A F8 In other words, separated by spaces. Now I realize there are a million ways to do this, but I would like a suggestion on which you think is the most efficient? Incidentally, I'm starting with a decimal value (23602210718), so maybe sprintf would be a direct way? ...Rene Best regards, René Fournier --- René Fournier GPS Police.NET 31, 1339 - 40th Ave NE Calgary, AB T2E 8N6 Canada Tel +1 (403) 250. Fax +1 (403) 291-2997 www.gpspolice.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sprintf?
I need to go from 1754210747 (decimal) to 17 54 21 a7 47 (hex per character) Basically, reformat the string for each character, converting it to Hex, and spacing after each two characters. Sprintf? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to make a PHP Socket client crash-proof?
I managed to solve the problem with the socket client hanging when the Server disappears. Actually, it is not hanging. What I discovered is that once the other end of the connection drops, it starts/continues reading on that socket ad infinitum. (I put a little counter in it, and can watch it count up). What I did to stop detect a gone connection, and then restart the socket, isn't elegant, doesn't use a socket_select() or non-blocking, but it DOES work. $i = 0; while(($buf = socket_read($socket,1,PHP_BINARY_READ)) !== false) { echo $i. \n; $i++; $data .= $buf; if(preg_match(/EOF/,$data)) { $msg_recv = 1; break; } if($i1) { $connect = false; break; } } Still, one day I would like to re-architect this. Seems a bit hackish. ...Rene On 9-Dec-04, at 1:19 PM, Richard Lynch wrote: Have you completely eliminated the possiblity of having a second, independent, completely unrelated client/socket which is used to *SEND* data to the server? client_get -- server client_send --- server They can both use your local database to share data, to whatever degree you deem necessary, but having one-way sockets for two different scripts is way more easier than trying to get a two-way socket to work, in my (limited) experience. If you MUST push forward with a two-way socket, try to determine the state of the world inside your infinite loop. Why aren't you breaking out of that loop? Can you do *anything* to break out? I suspect that once you have started SENDING data to the server, it's going to just keep waiting for you to send more. How do you signal the end of your data to be sent? Does the server understand that signal? -- Like Music? http://l-i-e.com/artists.htm ...René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to make a PHP Socket client crash-proof?
Hi all, I have a Socket Client that connects to a Server. (It is not multi-socket or multi-anything.) It is VERY simple. How it works: 0. CLIENT connects to SERVER. 1. CLIENT waits for incoming data. 2. If there is no data for a while, CLIENT sends a ping to the SERVER. 3. If the SERVER responds, CLIENT continues waiting. 4. If the SERVER doesn't respond (and a few seconds pass), CLIENT closes socket and restarts (Go to Step 0.) 5. Once in a while, CLIENT must send some data to the SERVER 6. If the SERVER acknowledges the data, CLIENT begins waiting again for data from the SERVER (Go to Step 1.) 7. If the SERVER doesn't acknowledge, CLIENT closes socket and restarts (Go to Step 0.) In a perfect world, the above script would run forever without trouble. Unfortunately, the world is not perfect. Sometimes, the Server dies or disappears unexpectedly, at which point my Client hangs and starts consuming 100% CPU. (The problem.) As I understand it, I must change the Client in a couple ways. 1. Set the Client's socket to NON-BLOCKING, so that it doesn't hang the script when the Server up and vanishes. 2. Use SOCKET_SELECT(). Now, I've read the docs and several good tutorials code examples, such as: http://us2.php.net/manual/en/function.socket-select.php http://us2.php.net/manual/en/function.socket-set-nonblock.php http://dave.dapond.com/socketselect.php.txt http://labs.jed.bz/HCJ/load.php.txt http://www.amk.ca/python/howto/sockets/ sockets.html#SECTION00051 http://www.catalyst.com/support/tutorials/tcpintro/page9.html Unfortunately, all examples appear to differ from my Client in very one important way: They do not contain lines 5-7. None of them have to periodically stop listening for incoming data and check if they need to write to the socket (like mine does). My Client MUST periodically check a database for new messages waiting to be sent. If there are any, it must write them to the Server. In my old code (which hangs when the Server disappears), I simply set the socket to blocking and give it a timeout of a couple seconds. So, every two seconds the Client times out, checks if there are any messages to send to the Server, sends them if there are, and then returns to waiting If it helps, I can post snippets of my code, before (working, but not crash-proof) and after (not working at all, just looping endlessly, really fast). Many thanks in advance for any suggestions you can offer. ...René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket trouble
I'm having some trouble with my socket client. I would like it to notice when the server is no longer there, and then reconnect. I have code for the reconnect, etc., but I can't figure out how to write the socket_read code so that it notices when the server is gone and then responds. Presently, my client just hangs (CPU goes to 100%, nothing happens.) Here's my code: while(($buf = socket_read($socket,1,PHP_BINARY_READ)) !== false) { $data .= $buf; if(preg_match(/TERMINATING/,$data)) { $msg_recv = 1; break; } } The PHP docs on socket_read suggest how this might be done: Note: socket_read() may return a zero length string () indicating the end of communication (i.e. the remote end point has closed the connection). Does this end of communication include cases when the socket server dies without gracefully disconnecting? How could my code check for this zero length string? Any help is much appreciated. Thanks! ...René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multiple web sites, one IP address...
I have a question that I'm not sure how to phrase (and google)... I know this is a little off-topic, but I was hoping some guru here might at least be able to point me in the right direction... --- I have several web sites (PHP-driven :-) that I want to host on my new xServe, which is sitting behind a regular router/firewall. I know how to forward port 80, etc., from the WAN side to the xServe on the LAN, and that's working fine. But now I would like to move several web sites that are presenting running on various ISPs to this server o' mine. This is where I'm kinda stuck. I know the xServe and Mac OS X Server can run multiple web sites/domains (the docs say so). But does each of my domains, registered with Network Solutions, need to point to a unique IP address? If they can all point to the same IP address (my router), then once the HTTP request is passed through the router, and port-forwarded to the xServe, how will the xServe know which request is for which domain/web site? If each domain needs its own IP address, then how can the all be forwarded to the same single router (which just has one IP address)? --- Asking this question I realize that there is some fundamental network stuff I don't understand. But the thing is, I don't know *what* I need to learn or in what order, so it's a little hard to start googling my ignorance away. If any of you know a good tutorial or how-to guide that more or less covers this kind of thing, I would very much appreciate it. ...Rene ...René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Output buffering (gzip) on Mac OS X 10.3.5
Zend (http://www.zend.com/zend/art/buffering.php) offers some suggestions on output buffering, which I am trying to implement on my web server (Mac OS X 10.3.5, Apache/1.3.29 (Darwin) PHP/4.3.6). So far, unsuccessfully. Has anyone got this working? Here's what I've got: ?php ob_start(ob_gzhandler); session_start(); // ...code ob_end_flush(); header('Content-Encoding: gzip'); ? I've tried numerous permutations of this and other code, but have yet to get anything to compress. Any ideas? ...René --- René Fournier www.renefournier.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] convert degrees to heading
I have to write a little function to convert a direction from degrees to a compass -type heading. 0 = West. 90 = North. E.g.: from: 135 degrees to: NW Now, I was planning to write a series of if statements to evaluate e.g., if ($heading_degrees 112.5 $heading_degrees 67.5) { $heading_compass = N; } The works, but it will require N, NNW, NNE, NE, NW, ENE, NWW... many IF statements. Can anyone think of a programatically more elegant and efficient way of converting this type of data? (I suppose this is not really a problem, just a curiosity.) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: convert degrees to heading
Works beautifully. Thanks! ...Rene On Friday, July 16, 2004, at 04:36 PM, Tim Van Wassenhove wrote: function degrees2compass($degrees) { $compass = array('N', 'NNW', 'NNE', 'NE', ...); $index = $heading_degrees / sizeof($compass); return $compass[$index]; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket Tutorial
Hi Andrew, This one helped me a lot: http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/ This isn't a tutorial, but good sample code for a multi-client chat server: http://dave.dapond.com/socketselect.phps ...Rene On Monday, July 5, 2004, at 12:39 PM, Andrew wrote: Hi guys, Can somebody provide a good PHP Socket Programming tutorial. I'm working on a chat server application. The client is XMLsocket based Flash movie. Thanks, Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Interactive Voice Response (IVR)
Hi, I am looking for an IVR system that would allow a person to call a number (via telephone), and then using the keypad to send commands that are processed by a PHP script whichafter hitting a mySQL database a few timesresponds with a value (success/failure) which then is played back to the person on the telephone. In other words: 1. Customer calls (telephone) a number. 2. Computer voice modem answers, IVR app says Welcome to _, Press 1 for, 2 for, 3 for, etc. 3. Customer presses 3. 4. IVR app executes a PHP command/script, returns with a result. I know there are commercial Windows apps that allow you to build voice menu trees... But what I need is to integrate that (the IVR portion) with my backend PHP/MySQL code. NO THANK YOU: A closed, Windows-only commercial IVR application. YES, PLEASE: an opensource IVR project that I could run on Mac OSX (my environment) and integrate into my PHP scripts. Sadly, sourceforge.net does not show anything like this in progress. (What projects are listed, such as CallXML, appear dead in the water.) Has anyone here had any experience with IVR apps insofar as they work with PHP applications? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] MapServer and PHP/MapScript
Anybody have any experience (good or bad) with MapServer? (http://mapserver.gis.umn.edu/) And if so, can you comment on how good or bad PHP/MapScript is? (http://mapserver.gis.umn.edu/doc42/phpmapscript-class-guide.html) Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: MapServer and PHP/MapScript
Can I ask, what platform/OS you are running it on? I am looking to build it for OSX 10.3... ...Rene On Monday, June 14, 2004, at 03:16 PM, Lester Caine wrote: René fournier wrote: Anybody have any experience (good or bad) with MapServer? (http://mapserver.gis.umn.edu/) And if so, can you comment on how good or bad PHP/MapScript is? (http://mapserver.gis.umn.edu/doc42/phpmapscript-class-guide.html) I have it running - but I haven't worked out how to make my own map yet :) -- Lester Caine - L.S.Caine Electronic Services -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Expedia.com
When Expedia.com is searching for flights, it displays a page with a little animated GIF progress bar, then display the results. How do they do that? How does the page sit idle until the query is finished, and then sends a new page with the results? I was thinking that they might use HTTP-REFRESH or something, and just keep hitting the database until the result is there. But is there a best way to do this? In my application, when the user clicks a certain button, it will take 10-20 seconds for the operation to completeduring that time I need the web browser to waiit for the data. I looked around for an article on this, but I'm not sure how to characterize this operation. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Expedia.com
I guess a better question would be, what is the best practices way of showing a Please wait... page while a server operation is performed (which could take 5 or 45 seconds), then make the page display the resulting data (via reload, or slow-load, or whatever)? Would love to find an article on this. ...Rene On Wednesday, June 9, 2004, at 05:56 PM, Michal Migurski wrote: When Expedia.com is searching for flights, it displays a page with a little animated GIF progress bar, then display the results. How do they do that? How does the page sit idle until the query is finished, and then sends a new page with the results? I was thinking that they might use HTTP-REFRESH or something, and just keep hitting the database until the result is there. But is there a best way to do this? In my application, when the user clicks a certain button, it will take 10-20 seconds for the operation to completeduring that time I need the web browser to waiit for the data. The progress bar goes by too quickly for me to tell, but perhaps they are using a slow-loading resource someplace on the page? E.g., an image whose content-length is 64, whose 64th byte does not get sent by the server until the query is complete. Combine that with a bit of javascript waiting for the image to load, and you should have basic loading-bar behavior. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Can someone explain this?
$dec = -71788; echo $dec.\n; $hex = dechex($dec).\n; $dec2 = hexdec($hex).\n; echo $dec2.\n; -= PRODUCES: =- -71788 3961595508 Is this something about signed versus unsigned integers? What I really would like to do is convert that negative number (-71788), which I suppose is unsigned to a signed integer (3961595508) without having to convert it to hex, then back to decimal. Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can someone explain this?
OK, that makes sense. But here's the problem: I receive binary data from SuperSPARC (big-endian), which I need to unpack according to certain documented type definitions. For example, let's say that $msg has the value 3961595508 and is packed as an unsigned long integer (on the remote SPARC). But when I receive it, and unpack it... $unpacked = unpack('Nval', $msg); // N for unsigned long integer, big-endian (SPARC) echo $unpacked[val]; ...the output value is -71788. (???) Which tells me that PHP is NOT unpacking $msg as an unsigned long integer, but rather as a signed integer (since unsigned integers cannot be negative). Now, thanks to your suggestions, I can convert that number back to an unsigned integeror at least make it positive. But I shouldn't have to convert it, should I? ...Rene On Tuesday, June 8, 2004, at 11:29 AM, Curt Zirzow wrote: * Thus wrote Ren Fournier ([EMAIL PROTECTED]): -= PRODUCES: =- -71788 3961595508 Is this something about signed versus unsigned integers? What I really would like to do is convert that negative number (-71788), which I suppose is unsigned to a signed integer (3961595508) without having to convert it to hex, then back to decimal. You have it backwords.. -71788 is signed and the 3961595508 is unsigned. But... ?php $dec = -71788; $unsigned = sprintf(%ul, $dec); print $unsigned; // == 3961595508 Do note that php doesn't have native unsigned numbers so doing something like this wont work right: printf(%d, $unsigned); // == 2147483647 So to convert it back you have to do something like: printf(%d, $unsigned+0); // == -71788 Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can someone explain this?
Thanks. The fact that this behaviour is a bug somehow makes me feel better. At least I'm not crazyor, not as crazy as I thought. ...Rene On Tuesday, June 8, 2004, at 12:57 PM, Curt Zirzow wrote: * Thus wrote Ren Fournier ([EMAIL PROTECTED]): Now, thanks to your suggestions, I can convert that number back to an unsigned integeror at least make it positive. But I shouldn't have to convert it, should I? Not necessarily, it mostly due to the limitation that php doesn't have unsigned integers. I have a patch for php that will return a unsigned integer as a string, but I havn't gotten it put into php yet. http://www.phpbuilder.com/lists/php-general/2003121/0526.php Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mapping solutions
I'm looking for a good mapping solution for a PHP project I'm working on, and wondered if any of you would be able to recommend one. Basically, I would like to be able to pass this Map Module several values: Latitude, longitude, map scale (e.g., 5KM x 5KM), and map resolution (500 pixels x 500 pixels), and have it return a GIF or JPEG which I can then send to the user's browser. (Additionally, it would be useful if I could pass more than one set of latitude/longitude values and have the map software display multiple points on the same map.) It seems unlikely that I could get my Host Provider to let me run third-party software like this on their servers, so I would probably have to install it on my ownwhich would likely end up being a Mac OS X box. Any suggestions? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP]
What's the difference between function myfunction() { } and function myfunction() { } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP]
Oops... I mean, what's the difference between function myfunction() { } and function myfunction() { } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP login script
I'm looking for some good, secure login code, and found the following article: http://www.devshed.com/c/a/PHP/Creating-a-Secure-PHP-Login-Script/ Not being much of a security expert, I was wondering if anyone here could say whether this code is any good? Or if there's a better one elsewhere? (I'm developing with MySQL, and do not know object-oriented PHP or PEARwhich this samplel uses.) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Secure login script
The link I posted previously is causing me some grief, apparently because I don't know the first thing about object-oriented PHP or PEAR. Here's the thing: If I MUST learn these two things in order to copy the security of the sample script, I will, but is it really necessary in your opinion? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] socket_select()
All the examples I see of socket_select() are on socket servers. But is it reasonable/feasible to use socket_select() on a socket client, that is receiving data periodically from a server (and when not receiving, doing something else)? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Blocking vs. Selecting
MY PROGRAM FLOW: Enter loop Wait incoming data If (incoming data) { do something } elseif (no data delay 5 seconds) { send ping to server return to top of loop } Of course, it's very simple. :-) But to make it work, I think I need to choose: 1. Timeout the socket_read() (nonblocking socket, etc.) or 2. Use socket_select. Here's my question: I have only one socket active in this application at any time. Is it appropriate to use socket_select with just one socket connection? And if I stop deselect that socket, and the server sends data while the scirpt is doing something else, will the data be lost, or will it wait o be read again once the script can give its attention to that connection? rEne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] World's simplest tutorial on socket_select???
I've seen a sweet script for a multi-client, multi-socket server in PHP (http://dave.dapond.com/socketselect.php.txt), but its purpose is quite different from mine, and it's about one billion times more complex than I need. I am building a SIMPLE socket client that makes ONE connection to ONE server, and waits for data (socket_read)... and when no data comes for a few seconds, does something else, then waits for data again. HOW SHOULD I APPROACH THIS?! PLEASE TOSS ME A BONE! (If you help me, I will buy you a pint of great beer.) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] I am in Socket Paradise
Please ignore my previous I-AM-SO-FRUSTRATED-I-AM-READY-FOR-A-JACKET-WITH-REALLY-LONG-SLEEVES posts. I have managed to solve my socket woes. My simple client works loops, timesout, loops again... elegantly. (I've learned not take those PHP warnings so seriously... and to clear socket errors.) Yippee! ..Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I am in Socket Paradise
On Thursday, May 20, 2004, at 04:17 PM, Chris W. Parker wrote: René Fournier mailto:[EMAIL PROTECTED] on Thursday, May 20, 2004 2:58 PM said: Please ignore my previous I-AM-SO-FRUSTRATED-I-AM-READY-FOR-A-JACKET-WITH-REALLY-LONG-SLEEVES posts. I have managed to solve my socket woes. My simple client works loops, timesout, loops again... elegantly. (I've learned not take those PHP warnings so seriously... and to clear socket errors.) so i admittedly stopped following your numerous threads after a while... mainly for the simple fact that i've never worked with sockets thus had nothing to contribute... but how praytell did you solve your problem? A combination of randomly following some (but not all) advice from this list and injecting enough debugging code to figure out myself what is going on. What threw me was the serious (but not Fatal) PHP Warnings that appeared when my socket was timing out. That, and I didn't clear the socket_last_error($socket). After ignoring the warnings, and clearing the error, and setting the socket options appropriately, the client loops, waits, executes and loops some more. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] World's simplest tutorial on socket_select???
On Thursday, May 20, 2004, at 05:15 PM, Curt Zirzow wrote: * Thus wrote Ren Fournier ([EMAIL PROTECTED]): I am building a SIMPLE socket client that makes ONE connection to ONE server, and waits for data (socket_read)... and when no data comes for a few seconds, does something else, then waits for data again. HOW SHOULD I APPROACH THIS?! PLEASE TOSS ME A BONE! (If you help me, I will buy you a pint of great beer.) Does that help earlier count for that great beer ;) Curt Sure... the next time you're in Calgary. :-) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I grab the contents of a web page?
On Thursday, May 20, 2004, at 06:42 PM, Brian Dunning wrote: On May 20, 2004, at 5:43 PM, raditha dissanayake wrote: I'm sure there's a really simple way to do this: how can I grab the source code of a specified web page and store it in a variable? Never mind, I found it: $string = get_file_contents('www.123.com'); - Brian You probably mean... $string = file_get_contents(http://www.123.com;); (The protocol bit is important too.) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would a socket be unavailable?
On Thursday, May 13, 2004, at 08:05 PM, Vail, Warren wrote: Don't know if this will help, but can you confirm whether your while loop is failing on the first time through or a subsequent time through (perhaps by echoing something each time through)? No, it doesn't fail the first time. It runs through the loop several times, and fails ONLY once it timesout (because the server is sending no more data). Then, the next time it loops, it fails again. That said, I am going to shortly repost the program flow (in simplified form), so you guys can see the issue. (Someone kindly pointed out that as this thread has grown, the original issue is no longer clear.) Thanks guys for helping. ...rene Warren Vail -Original Message- From: René Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 5:13 PM To: Vail, Warren Cc: php Subject: Re: [PHP] Why would a socket be unavailable? Hi Warren, There is only one process, and I'm sure I have only one IP address. It's just one script that loops. At the top of the loop, it waits to socket_read some data. If no data appears, I want it to timeout so that it can send the server a ping (which I must do). THAT is where the problem starts. If I don't bother making the socket_read timeout, the loop works beautifully-it just waits and waits at socket_read, and then when data appears, it does its thing, then goes back to the top of the loop and waits again. It's when I set the timeout option, and then it DOES actually time out (because there is no data for several seconds), that it no longer is able to socket_read data from the connection. .Rene On Thursday, May 13, 2004, at 05:57 PM, Vail, Warren wrote: So you have two processes running, one which is waiting on the socket connection and another, which we have seen, to establish the connection. Doesn't sound to me to be related to performing blocked/non-blocked connections. What are the odds that you have multiple IP addresses on your machine? Can you confirm that both of your processes are using the same IP address (or the ip address of the other process)? Warren Vail -Original Message- From: René Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 4:49 PM To: Vail, Warren Cc: php Subject: Re: [PHP] Why would a socket be unavailable? There is no firewall-it's all running locally, on my iBook (with Firewall off). You know, I really wish it WAS the firewall. :-) I really can't believe this little problem I'm encountering is because of some bug in the Socket library. I mean, what I'm doing is so simple, and I'm sure hundreds of other PHP programmers have done this before, like, a million times. The whole script is actually very simple: Enter loop If data is received, handle it If data is not received in several seconds, send server a ping .Rene On Thursday, May 13, 2004, at 05:40 PM, Vail, Warren wrote: There is another kind of blocking you could be running into (other than the type mentioned in the manual) and it was eluded to before. What are the odds you are going through a firewall to get to the server. Firewalls will reject attempts to connect to unauthorized sockets on protected machines. Warren Vail -Original Message- From: René Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 4:24 PM To: [EMAIL PROTECTED] Cc: php Subject: Re: [PHP] Why would a socket be unavailable? On Thursday, May 13, 2004, at 05:13 PM, Daniel Clark wrote: http://www.php.net/manual/en/ref.sockets.ph Yes, I've read that page... many times. It has not helped me. That is why I am posting my problem here, in that hopes that someone can help. (I don't mean to be completely helpless, but I just don't yet understand blocking/non-blocking sockets, and the parameters associated, since they are not well-documented. Someone said I shouldn't complain about this-and I'm not-since the functions are marked Experimental. But this is precisely why I'm posting the question here.) .Rene I just read something about sock warnings this morning. It said sometimes they drop off, and to ignore the warnings, but capture the errors. I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket client can do one thing (loop), but not the other (loop, timeout, loop again)
Hello everyone, I really appreciate the suggestions so far with my socket client problem. Somebody suggested I repost the issue with the program flow and code, to clarify the situation (a good idea). So here it is: To sumarrize: My socket client runs fine when all it does is (1) wait for data from the server (2) respond to server message (3) then wait again (ad infinitum). E.g., ---THIS WORKS-- Setup and open TCP socket Send a Password_DS to the Server Send a Resend_DS to the Server Enter infinite loop: Wait for messages from the Server Upon receipt of a Send_DS from the Server Respond with a Send_DS_Ack Upon receipt of a Ping_DS from the Server Respond with a Ping_DS_Ack Upon receipt of a Status_DS from the Server Respond with a Status_DS_Ack ---THIS WORKS-- Again, the client loops fine and works wellUNTIL I I try to add one feature: If the Server doesn't send a message for more than five seconds, the socket_read should send Ping_DS to the Server to see if it's still alive, and then, if it is, continue to the top of the loop and wait for another message from the Server. ---THIS DOESN'T WORK-- Setup and open TCP socket Send a Password_DS to the Server Send a Resend_DS to the Server Enter infinite loop: Wait for messages from the Server Upon receipt of a Send_DS from the Server Respond with a Send_DS_Ack Upon receipt of a Ping_DS from the Server Respond with a Ping_DS_Ack Upon receipt of a Status_DS from the Server Respond with a Status_DS_Ack - Periodically, send a Ping_DS to the Server - If the Ping_DS transmit fails - Clean-up and restart the socket connection - If a Ping_DS_Ack is not received from the Server - Clean-up and restart the socket connection ---THIS DOESN'T WORK-- ---PROGRAM OUTPUT-- Socket created. Socket connected to 192.168.0.13:9500. SERVER - CLIENT: 18 (PASSWORD_DS) SERVER - CLIENT: 19 (PASSWORD_DS_ACK) SERVER - CLIENT: 3 (RESEND_DS) MESSAGE RECEIVED SERVER - CLIENT: 23 (STATUS_DS) SERVER - CLIENT: 24 (STATUS_DS_ACK) MESSAGE RECEIVED SERVER - CLIENT: 16 (RESEND_DS_ACK) PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 ---PROGRAM OUTPUT-- ---MY CODE (WHICH DOESN'T WORK)-- $msg_recv = 3; $timeout = array('sec' = 5, 'usec' = 0); // ENTER LOOP do { $data = ; socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; if(preg_match(/ENX/,$data)) { $msg_recv = 1; break; } elseif ($error = socket_last_error($socket)) { $msg_recv = 0; echo \nTIMEOUT: SOCKET ERROR [$error]: . socket_strerror($error); break; } } if ($msg_recv == 1) { echo \n\n\nMESSAGE RECEIVED\n; // RECEIVED MESSAGE $msg_type = get_msg_type($data); recv_msg($msg_type); // RESPONSE switch ($msg_type) { case 1: // SEND_DS -- PROCESS MESSAGE, RESPOND $msg_body = get_msg_body($data); send_msg(,$cn[SEND_DS_ACK]); break; case 13: // PING_DS -- RESPOND send_msg(,$cn[PING_DS_ACK]); break; case 23: // STATUS_DS -- UP AND RUNNING -- RESPOND send_msg(,$cn[STATUS_DS_ACK]); break; case 16: // RESEND_DS_ACK -- DO NOTHING break; case 25: // DISCONNECT_DS -- ACKNOWLEDGE, CLOSE SOCKET, REOPEN socket_close($socket);
[PHP] Breaks on socket_read
Can anyone suggest why this script (well, part of the script) fails on the while(($bug=socket_read... line after it successfully loops several times? (Of course, it is only after it timesout, but that is what I need it to do.) ---CODE-- $msg_recv = 3; $timeout = array('sec' = 5, 'usec' = 0); // ENTER LOOP do { $data = ; socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; ---OUTPUT-- PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 65 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Missing data types?
I need to pack() data in PHP according to a typedef'ed C format structure, but there seems to be two problems (as per the docs: http://ca.php.net/manual/en/function.pack.php). First, in PHP there is no format option for long signed integers, big-endian byte order, just signed long (always 32 bit, machine byte order). Or am I missing something? Secondand I guess this is not a problem with PHP per se, just a question of interpretationthe client specifications call for a certain 10-digit string to be packed as char ( char[10] ). But char is just a single character right? Or do you think the docs essentially mean packing it as an alpha? (Whose length can be specified.) $str = 1234567890; $packed = pack(a10string,$str); ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket looping challenge
Hi all, Still encountering some challenges with my socket loop. Basically, I need this socket client to wait to read incoming data, but if nothing happens for more than three seconds, I want it to do something, then return to waiting (for another three seconds). I've got some good help from Curt and Tom (thanks guys), but there are evidently still issues with my code. Here's simplified snippet: - CODE - // INFINITE LOOP $msg_recv = false; $timeout = array('sec' = 3, 'usec' = 0); socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); do { while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; if(preg_match(/ENX/,$data)) { $msg_recv = true; break; } elseif ($error = socket_last_error($socket)) { $msg_recv = false; echo \nTIMEOUT: SOCKET ERROR [$error]: . socket_strerror($error); break; } } if ($msg_recv == true) { echo \nMESSAGE RECEIVED\n; $msg_recv = false; } else { echo \nTIMEOUT: MESSAGE NOT RECEIVED\n; $msg_recv = false; } $data = ; } while ($connection == true); - OUTPUT - MESSAGE RECEIVED MESSAGE RECEIVED PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 61 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 61 TIMEOUT: MESSAGE NOT RECEIVED PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 61 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 61 TIMEOUT: MESSAGE NOT RECEIVED -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why would a socket be unavailable?
I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Socket looping challenge
The script doesn't even get that first while condition line. It loops a few times (while receiving messages), then when no more messages are coming from the server, and it times-out, it breaks out of the while, then returns to the top again, where it that while condition returns the error Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable. This line... while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { ...is what returns the error. The whole loop (which needs to keep running). $msg_recv = 3; do { $data = ; socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { // THIS IS WHERE IT CHOKES $data .= $buf; if(preg_match(/ENX/,$data)) { $msg_recv = 1; break; } elseif ($error = socket_last_error($socket)) { $msg_recv = 0; echo \nTIMEOUT: SOCKET ERROR [$error]: . socket_strerror($error); break; } } if ($msg_recv == 1) { echo \nMESSAGE RECEIVED\n; $msg_recv = 3; } elseif ($msg_recv == 0) { echo \nTIMEOUT: MESSAGE NOT RECEIVED\n; $msg_recv = 3; } } while ($connection == true); And the output: MESSAGE RECEIVED MESSAGE RECEIVED PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 64 Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 64 On Thursday, May 13, 2004, at 04:44 PM, Tom Rogers wrote: Hi, Friday, May 14, 2004, 5:21:10 AM, you wrote: RF Hi all, RF Still encountering some challenges with my socket loop. Basically, I RF need this socket client to wait to read incoming data, but if nothing RF happens for more than three seconds, I want it to do something, then RF return to waiting (for another three seconds). I've got some good help RF from Curt and Tom (thanks guys), but there are evidently still issues RF with my code. Here's simplified snippet: you need to use break 2; to exit the while and the do - while or set $connection = false; -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would a socket be unavailable?
There is no firewall. I'm running this locally. On Thursday, May 13, 2004, at 05:00 PM, raditha dissanayake wrote: #1 cause for socket failures happen to be firewalls. René Fournier wrote: I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- Raditha Dissanayake. - http://raditha/megaupload/upload.php Sneak past the PHP file upload limits. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would a socket be unavailable?
On Thursday, May 13, 2004, at 05:13 PM, Daniel Clark wrote: http://www.php.net/manual/en/ref.sockets.ph Yes, I've read that page... many times. It has not helped me. That is why I am posting my problem here, in that hopes that someone can help. (I don't mean to be completely helpless, but I just don't yet understand blocking/non-blocking sockets, and the parameters associated, since they are not well-documented. Someone said I shouldn't complain about thisand I'm notsince the functions are marked Experimental. But this is precisely why I'm posting the question here.) ...Rene I just read something about sock warnings this morning. It said sometimes they drop off, and to ignore the warnings, but capture the errors. I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would a socket be unavailable?
There is no firewallit's all running locally, on my iBook (with Firewall off). You know, I really wish it WAS the firewall. :-) I really can't believe this little problem I'm encountering is because of some bug in the Socket library. I mean, what I'm doing is so simple, and I'm sure hundreds of other PHP programmers have done this before, like, a million times. The whole script is actually very simple: Enter loop If data is received, handle it If data is not received in several seconds, send server a ping ...Rene On Thursday, May 13, 2004, at 05:40 PM, Vail, Warren wrote: There is another kind of blocking you could be running into (other than the type mentioned in the manual) and it was eluded to before. What are the odds you are going through a firewall to get to the server. Firewalls will reject attempts to connect to unauthorized sockets on protected machines. Warren Vail -Original Message- From: Ren Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 4:24 PM To: [EMAIL PROTECTED] Cc: php Subject: Re: [PHP] Why would a socket be unavailable? On Thursday, May 13, 2004, at 05:13 PM, Daniel Clark wrote: http://www.php.net/manual/en/ref.sockets.ph Yes, I've read that page... many times. It has not helped me. That is why I am posting my problem here, in that hopes that someone can help. (I don't mean to be completely helpless, but I just don't yet understand blocking/non-blocking sockets, and the parameters associated, since they are not well-documented. Someone said I shouldn't complain about this-and I'm not-since the functions are marked Experimental. But this is precisely why I'm posting the question here.) .Rene I just read something about sock warnings this morning. It said sometimes they drop off, and to ignore the warnings, but capture the errors. I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would a socket be unavailable?
Hi Warren, There is only one process, and I'm sure I have only one IP address. It's just one script that loops. At the top of the loop, it waits to socket_read some data. If no data appears, I want it to timeout so that it can send the server a ping (which I must do). THAT is where the problem starts. If I don't bother making the socket_read timeout, the loop works beautifullyit just waits and waits at socket_read, and then when data appears, it does its thing, then goes back to the top of the loop and waits again. It's when I set the timeout option, and then it DOES actually time out (because there is no data for several seconds), that it no longer is able to socket_read data from the connection. ...Rene On Thursday, May 13, 2004, at 05:57 PM, Vail, Warren wrote: So you have two processes running, one which is waiting on the socket connection and another, which we have seen, to establish the connection. Doesn't sound to me to be related to performing blocked/non-blocked connections. What are the odds that you have multiple IP addresses on your machine? Can you confirm that both of your processes are using the same IP address (or the ip address of the other process)? Warren Vail -Original Message- From: Ren Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 4:49 PM To: Vail, Warren Cc: php Subject: Re: [PHP] Why would a socket be unavailable? There is no firewall-it's all running locally, on my iBook (with Firewall off). You know, I really wish it WAS the firewall. :-) I really can't believe this little problem I'm encountering is because of some bug in the Socket library. I mean, what I'm doing is so simple, and I'm sure hundreds of other PHP programmers have done this before, like, a million times. The whole script is actually very simple: Enter loop If data is received, handle it If data is not received in several seconds, send server a ping .Rene On Thursday, May 13, 2004, at 05:40 PM, Vail, Warren wrote: There is another kind of blocking you could be running into (other than the type mentioned in the manual) and it was eluded to before. What are the odds you are going through a firewall to get to the server. Firewalls will reject attempts to connect to unauthorized sockets on protected machines. Warren Vail -Original Message- From: Ren Fournier [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 4:24 PM To: [EMAIL PROTECTED] Cc: php Subject: Re: [PHP] Why would a socket be unavailable? On Thursday, May 13, 2004, at 05:13 PM, Daniel Clark wrote: http://www.php.net/manual/en/ref.sockets.ph Yes, I've read that page... many times. It has not helped me. That is why I am posting my problem here, in that hopes that someone can help. (I don't mean to be completely helpless, but I just don't yet understand blocking/non-blocking sockets, and the parameters associated, since they are not well-documented. Someone said I shouldn't complain about this-and I'm not-since the functions are marked Experimental. But this is precisely why I'm posting the question here.) .Rene I just read something about sock warnings this morning. It said sometimes they drop off, and to ignore the warnings, but capture the errors. I get this output: PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 63 From this code: do { socket_set_block($socket); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { [...] And it's failing at while. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Constant questions
Hi, I have two questions involving Constants. 1. I want to refer to a refer to a Constant by its value (which is unique), and return its name. E.g.,: define (SEND_DS,1); define (SEND_DS_ACK,2); define (RESEND_DS,3); define (STARTUP_DS,12); For example, if I receive 3, I would like to echo RESEND_DS--the name of the constant. Is there a simply way to do this? Or am I better using an Associative Array (which is what I was thinking)? Then I could such refer to an element by its key or value (both of which are unique). I suppose this more of a performance/elegance issue, than outright problem. Just curious what you think. 2. Let's say I have a Constant called MY_NAME, the value of which is Rene, and I pass it to a function, such as: function example ($val) { echo ???; } example (MY_NAME); Such that the output will be MY_NAME. If I echo $val, the output will be Rene. But I want to see the constants Name, not Value. Any ideas? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Breaking out of a loop...
Hi, I have this code (below) that waits for particular data to come over the socket (ENX), at which point it breaks out of the loop and does other things. Presently, it will loop forever, until it receives ENXa good startbut I also need it to break-out if the loop runs longer than five seconds. This is where I'm having a problem. It seems that it is only reading once data comes over the socket, so it is stuck on that first 'while' line (while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {). $timer = time(); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; $elapsed = time() - $timer; if(preg_match(/ENX/, $data)) { break; } elseif ($elapsed 5) { echo TOO LONG!\n; break; } } Maybe set non-blocking / blocking socket is the answer? Only problem is I can't find much [good] documentation describing what blocking and non-blocking sockets are good for, etc. Any ideas? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Breaking out of a loop...
Thanks for the help, but I now get the error PHP Warning: socket_set_option() expects exactly 4 parameters, 3 given in /Users/test/cr.php on line 51 when I run the script. Also, it still seems to just wait on that while line, instead of skipping to the } elseif ($elapsed 5) { and breaking from the loop (which is what I want it to do). (Is it just me, or is the PHP documentation on socket_set_block and socket_set_option a bit too sparse? I mean, where do you find the docs on those options and values?) - socket_set_block($socket); socket_set_option($socket,SO_RCVTIMEO,5000); // milliseconds iirc do { $timer = time(); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; $elapsed = time() - $timer; if(preg_match(/ENX/, $data)) { break; } elseif ($elapsed 5) { echo TOO LONG!\n; break; } if ($error = socket_last_error($socket)) { echo socket error [$error]: . socket_strerror($error); } } - On Wednesday, May 12, 2004, at 03:41 PM, Curt Zirzow wrote: * Thus wrote Ren Fournier ([EMAIL PROTECTED]): Hi, I have this code (below) that waits for particular data to come over the socket (ENX), at which point it breaks out of the loop and does other things. Presently, it will loop forever, until it receives ENXa good startbut I also need it to break-out if the loop runs longer than five seconds. This is where I'm having a problem. It seems that it is only reading once data comes over the socket, so it is stuck on that first 'while' line (while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {). $timer = time(); while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; $elapsed = time() - $timer; if(preg_match(/ENX/, $data)) { break; } elseif ($elapsed 5) { echo TOO LONG!\n; break; } } Maybe set non-blocking / blocking socket is the answer? Only problem is I can't find much [good] documentation describing what blocking and non-blocking sockets are good for, etc. Any ideas? Thanks. blocking - wait for response or till timeout non-blocking - return right away If you use blocking and then set the timeout for the read, you can just check for socket_last_error() after the loop. socket_set_block($socket); socket_set_option($socket, SO_RCVTIMEO, 5000); // milliseconds iirc while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { //... } if ($error = socket_last_error($socket) ) { echo socket error [$error]: . socket_strerror($error); } or something like that. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] To pack(), or not to pack()
Hi, I'm developing a PHP program that must send data, over a socket connection, to a server. The server requires the data in a particular format, e.g.: FORMAT: 3-byte delimiter - Message Length (N = 4 bytes) - Message Type (4 bytes) - Message Body (N - 4 bytes) - 3-byte Delimiter SAMPLE MESSAGE: STX00110018Hello WorldENX The sparse documentation *seems* to indicate that the message data must be in binary format. The reason I say seems is that the docs say the data must be in a particular byte order (bigendian, I think, 'cause the server is running on SuperSPARC). It also talks about default integer size of 32 bits, unsigned char, blah, blah, blahstuff I normally never worry about with PHP. All the sample code is in C, which I don't know. I'm a one-trick (PHP) pony. Now, as I understand it, socket_write($socket, $data) by default will send $data in ASCII formatright? But if I must send this message in binary, then would I use pack() to convert the ASCII to binary? ..Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unsigned long int
I don't know C, but I was wondering if it is possible to: 1. Define 32-bit integer in PHP, called $val (max value of $val); 2. Assign the value of 10 to $val. 3. Pack $val to a binary variable ($bin_var); ...such that $val is only equal to 10, but it is occupying 32-bits of data... (In case you were wondering, am I quite lost, yes, I am.) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Binary to ASCII
When reading from a Socket Server, my Socket Client retrieves data that includes ASCII and binary data: while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { $data .= $buf; if(preg_match(/ENX/, $data)) break; } echo RESPONSE: .$data.\n; The output looks like: RESPONSE: STXThe system is up and running.ENX Between the STX and The system is up... are 8 bytes of binary data (which this case appear as an ampersand), which I want to extract from $data, split into two 4 byte variables, and convert back into integers. I suspect that I need unpack() at some point, but any ideas how to extract and split the binary data from this string? (Sometimes, the binary data is not visible, but it's still there.) ...Rene PS. Thanks guys for the earlier advice with pack()--which worked. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket server with multiple connections
I've gone through a few good socket client and server tutorials (such as http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/), and have got the samples working. What I'm trying to do now is write a simple Socket Server that will accept multiple connections, do its thing, and keep running. This Zend tutorial (http://www.zend.com/zend/tut/tutorial-staub3.php) does explain the concepts pretty well, but I cannot for the life of me get the sample code to run. The user comments noticed a couple typos, and other errors, which I've fixed, but still... no dice. I'm running PHP Version 4.3.4 on Mac OSX 10.2.8. Here's the error message: -- [Valhalla:~/Sites/sockets/test] rene% /usr/local/php/bin/php s9.php PHP Notice: Undefined offset: 0 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 0 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 1 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 1 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 2 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 2 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 3 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 3 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 4 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 4 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 5 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 5 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 6 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 6 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 7 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 7 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 8 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 8 in /Users/me/Sites/sockets/test/s9.php on line 20 PHP Notice: Undefined offset: 9 in /Users/me/Sites/sockets/test/s9.php on line 20 Notice: Undefined offset: 9 in /Users/me/Sites/sockets/test/s9.php on line 20 -- Here my code: -- ? // VARIABLES set_time_limit(0); $server_ip = 192.168.0.200; $server_port = date(i).000; // create socket $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die(Could not create socket\n); // bind socket to port $result = socket_bind($socket, $server_ip, $server_port) or die(Could not bind to socket\n); // start listening for connections $result = socket_listen($socket, 3) or die(Could not set up socket listener\n); echo Waiting for connections...\n; // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die(Could not accept incoming connection\n); echo Received connection request\n; // write a welcome message to the client $welcome = Welcome to the Server!\n .chr(0); socket_write($spawn, $welcome, strlen ($welcome)) or die(Could not send connect string\n); // keep looping and looking for client input do { // read client input $input = socket_read($spawn, 1024) or die(Could not read input\n); if (trim($input) != ) { echo Received input: $input\n; // if client requests session end if (trim($input) == END) { // close the child socket // break out of loop socket_close($spawn); break; } // otherwise... else { // reverse client input and send back $output = strtoupper($input); socket_write($spawn, $output) or die(Could not write output\n); echo Sent output: . trim($output) . \n; } } } while (true); // close primary socket socket_close($socket); echo Socket terminated\n; ? --- Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket Server problem
I'm working through Ori Staub's excellent Socket Server tutorial (http://www.zend.com/zend/tut/tutorial-staub3.php), but can't get the sample server working. I've read the user comments and fixed a couple things, but still, no dice. Here's the error I receive: [Valhalla:~/Sites/test] rene% /usr/local/php/bin/php s9.php PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 PHP Notice: Undefined variable: client in /Users/rene/Sites/test/s9.php on line 30 ...and then it just hangs. Since I'm so new to sockets, and probably don't yet grasp the concepts perfectly, I'm a little lost where to start. Any ideas? Here's my code: ? // VARIABLES set_time_limit(0); $server_ip = 192.168.0.200; $server_port = 7000; $max_clients = 10; // Array will hold client info $clients = Array(); // Create TCP stream socket $sock = socket_create(AF_INET,SOCK_STREAM,0); // Bind the socket socket_bind($sock,$server_ip,$server_port) or die('Could not bind to address'); // Start listening... socket_listen($sock); // Loop while (true) { // Setup clients listen socket for reading $read[0] = $sock; for ($i = 0; $i $max_clients; $i++) { if ($client[$i]['sock'] != null) $read[$i+1] = $client[$i]['sock']; } // Set up a blocking call to socket_select() $ready = socket_select($read,$null=null,$null=null,$null=null); // If a new connection is being made add it to the client array if (in_array($sock,$read)) { $cur_conn = count($client); for ($i = 0; $i $cur_conn; $i++) { if ($client[$i]['sock'] == null) { $client[$i]['sock'] = socket_accept($sock); break; } elseif ($i == $max_clients - 1) print (too many clients); } if (--$ready = 0) continue; } // end if in_array // If a client is trying to write, deal with it $cur_conn = count($client); for ($i = 0; $i $cur_conn; $i++) // for each client { if (in_array($client[$i]['sock'],$read)) { $input = socket_read($client[$i]['sock'],1024); if ($input == null) { // Zero length string meaning disconnected unset($client[$i]); } if ($input == 'exit') { // requested disconnect socket_close($client[$i]['sock']); } elseif ($input) { // strip whitespace and writeback to user $output = ereg_replace([ \t\n\r],,$input).chr(0); $socket_write($client[$i]['sock'],$output); } } else { // Close the socket socket_close($client[$i]['sock']); unset($client[$i]); } } } // end while // Close the master sockets socket_close($sock); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket client application
Hi, I've gone through several good PHP sockets tutorials, but all of them seem to focused on making socket servers. What I actually need to do is write a socket client. There's an app runnning on a distant server that accepts incoming TCP connections at such-and-such an IP address and port, and then responds to various commands and issues standard responses, etc.---I need to build the app that talks to it. Now maybe I'm missing something really obvious, but I can't find any tutorials on what such a socket client app might look like. The client I need to build must maintain the connection once started. Any ideas?? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regular expressions
I'm trying to 'clean up' some text that is extracted from a web directory, and I need to use (I think) preg_replace or ereg_replace, etc. I've read a bunch of tutorials, but none of them seem to cover the particular thing I want to do. Here's an example of text I need to process: - J. Smith ( More Info ) map driving directions add to My Directory update or remove Did you go to High School with J. Smith? B. Dixon ( More Info ) map driving directions add to My Directory update or remove Did you go to High School with B. Dixon? M. Jones ( More Info ) map driving directions add to My Directory update or remove Did you go to High School with M. Jones? - The above is a string. I want to eliminate, for example, all the lines that say Did you... ?, but I don't know how to refer to them because they are each a little different (because of the name). I know regular expressions can do this, but I can't seem to wrap my mind around the necessary arguments... This being my first foray into regex. I've written feeble stuff like: $result = ereg_replace(Did you go\[a-zA-Z]\?,,$result); But of course it doesn't work. Any ideas? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Problems with imagejpeg
I have a function that [is meant to] check if an image is greater than a certain width and height, and if it is, downsample it. The checking part works fine. Downsampling is happening though. Here's what I've got ($file = /somedirectory/photo.jpg): $src_img=imagecreatefromJPEG($file); $dst_img=imagecreatetruecolor($new_width,$new_height); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_width,$new_height,$siz e[0],$size[1]); imagejpeg($dst_img,$file,$img_quality); Any ideas? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] HELP! -- Problem with imagejpeg()
Hello, I have a function that is meant to check if an image is greater than a certain width and height, and if it is, downsample it. The checking part works fine. Downsampling is not happening though. Here's what I've got (btw, $file = /somedirectory/photo.jpg): $src_img=imagecreatefromJPEG($file); $dst_img=imagecreatetruecolor($new_width,$new_height); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_width,$new_height,$siz e[0],$size[1]); imagejpeg($dst_img,$file,$img_quality); Any ideas? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] GD question
I want to write a function the creates a new image composited from a 3x3 tile. The idea is that the center tile will be a photo, and the surrounding eight images will constitute a border and shadow to the composited image. So... The eight border/shadow images will always be the same, but the center image will be unique. Anyways, I've been playing with GD functions for a little while, and would appreciate any suggestions on how to accomplish this. I haven't been able to find a good tutorial on this kind of thing specificallycompositing tiles of images into a single image. Any ideas? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sweet PHP backup / dump function for MySQL database
Right now, I'm using phpMyAdmin to periodically backup/dump a client MySQL database to a textfile (from which one can simply restore the database if it ever got corrupted). I'm also working on a super-simple CMS for the client to use themselves. I would like the client to also be able to easily backup his web site's MySQL database to a textfile and have that textfile emailed to whatever address he specifies. Sort of a two step approach: Enter email _ Backup and send database (click) I imagine someone somewhere has written a very nice function for doing this, which might take a few parameters, such as database, destination email address, etc. The main thing is that the function include complete inserts, extended inserts, backquotes, etc. Anyone have a sweet function like this they wanna share, and in so doing make the world a better place? :-) ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_field_type() ...
...will say if a field is of type ENUM, but not its possible values (including default). Does anyone know how I can fetch possible values of a field type of ENUM? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an uploaded file...
Ah, man, I just found my problem, and do I ever feel stupid... Thought I'd share it to highlight the it's right in front of one's nose feeling: copy($_FILES['userfile']['tmp_name']... ...was a sample code snippet. I had just copied and pasted it without changing the userfile partand since there was no 'userfile' in my form, it would never have worked. Using my own variable pointer $fld works. Thus: copy($_FILES[$fld]['tmp_name']. ...works. And that is all. In any case, thanks for the suggestions. ...Rene On Wednesday, October 29, 2003, at 11:28 PM, John Nichel wrote: Ren Fournier wrote: I've added a path, but still no success Does your webserver (Apache?) have write permission to the directory you're trying to move the file too? -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Copying an uploaded file...
I'm trying to get a little upload script working... But I can't seem to copy the tmp file to my local web directory (btw, do I really need to specify the path, or can I just use a filename, and the file will be written to the same directory as the PHP script??). Anyway, here is the code: $realname = $_FILES['userfile']['name']; if(copy($_FILES['userfile']['tmp_name'], '/Users/rene/Sites/renefournier/titan/res/'.$realname)) { echo $realname.' uploaded'; } else { echo $realname.' could not be uploaded'; } echo 'br'; echo name: .$_FILES[$fld]['name']; echo 'br'; echo type: .$_FILES[$fld]['type']; echo 'br'; echo size: .$_FILES[$fld]['size']; echo 'br'; echo tmp: .$_FILES[$fld]['tmp_name']; echo 'br'; Here is the output: could not be uploaded name: web_share.gif type: image/gif size: 13370 tmp: /var/tmp/phpNqigbO Thanks for any ideas. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an uploaded file...
Thanks John. I've simplified and improved the quote per your suggestions, but still no dice. (I'[m running OS X 10.2.8.) Here is the code: // MOVE FILE if (move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile'][ 'name'])) { echo Success!; } else { echo NO!!!; } Here are the results: NO!!! Array ( [img_photo] = Array ( [name] = apache_pb.gif [type] = image/gif [tmp_name] = /var/tmp/phpvnTFqr [error] = 0 [size] = 2326 ) ) Should the tmp directory maybe be set elsewhere? (If so, how can that be done? I've looked at the httpd.conf file, but there is no entry for upload tmp directory.) Many thanks in advance. ...Rene On Wednesday, October 29, 2003, at 12:41 PM, John Nichel wrote: René Fournier wrote: I'm trying to get a little upload script working... But I can't seem to copy the tmp file to my local web directory (btw, do I really need to specify the path, or can I just use a filename, and the file will be written to the same directory as the PHP script??). Anyway, here is the code: $realname = $_FILES['userfile']['name']; if(copy($_FILES['userfile']['tmp_name'], '/Users/rene/Sites/renefournier/titan/res/'.$realname)) { echo $realname.' uploaded'; } else { echo $realname.' could not be uploaded'; } PHP has built in functions to move the temp file for you http://us3.php.net/manual/en/function.move-uploaded-file.php echo 'br'; echo name: .$_FILES[$fld]['name']; echo 'br'; echo type: .$_FILES[$fld]['type']; echo 'br'; echo size: .$_FILES[$fld]['size']; echo 'br'; echo tmp: .$_FILES[$fld]['tmp_name']; echo 'br'; Do you know about print_r? pre ?php print_r ( $_FILES ); ? /pre -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an uploaded file...
Thanks John. I've simplified and improved the quote per your suggestions, but still no dice. (I'[m running OS X 10.2.8.) Here is the code: // MOVE FILE if (move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile'][ 'name'])) { echo Success!; } else { echo NO!!!; } Here are the results: NO!!! Array ( [img_photo] = Array ( [name] = apache_pb.gif [type] = image/gif [tmp_name] = /var/tmp/phpvnTFqr [error] = 0 [size] = 2326 ) ) Should the tmp directory maybe be set elsewhere? (If so, how can that be done? I've looked at the httpd.conf file, but there is no entry for upload tmp directory.) Many thanks in advance. ...Rene On Wednesday, October 29, 2003, at 12:41 PM, John Nichel wrote: René Fournier wrote: I'm trying to get a little upload script working... But I can't seem to copy the tmp file to my local web directory (btw, do I really need to specify the path, or can I just use a filename, and the file will be written to the same directory as the PHP script??). Anyway, here is the code: $realname = $_FILES['userfile']['name']; if(copy($_FILES['userfile']['tmp_name'], '/Users/rene/Sites/renefournier/titan/res/'.$realname)) { echo $realname.' uploaded'; } else { echo $realname.' could not be uploaded'; } PHP has built in functions to move the temp file for you http://us3.php.net/manual/en/function.move-uploaded-file.php echo 'br'; echo name: .$_FILES[$fld]['name']; echo 'br'; echo type: .$_FILES[$fld]['type']; echo 'br'; echo size: .$_FILES[$fld]['size']; echo 'br'; echo tmp: .$_FILES[$fld]['tmp_name']; echo 'br'; Do you know about print_r? pre ?php print_r ( $_FILES ); ? /pre -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an uploaded file...
I've added a path, but still no success On Wednesday, October 29, 2003, at 05:11 PM, John Nichel wrote: René Fournier wrote: Thanks John. I've simplified and improved the quote per your suggestions, but still no dice. (I'[m running OS X 10.2.8.) Here is the code: // MOVE FILE if (move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile' ][ 'name'])) { echo Success!; } else { echo NO!!!; } Here are the results: Give it a path for the file to be moved too... if(move_uploaded_file($_FILES['userfile']['tmp_name'], /path/to/save/ . $_FILES['userfile']['name'])) { NO!!! Array ( [img_photo] = Array ( [name] = apache_pb.gif [type] = image/gif [tmp_name] = /var/tmp/phpvnTFqr [error] = 0 [size] = 2326 ) ) Should the tmp directory maybe be set elsewhere? (If so, how can that be done? I've looked at the httpd.conf file, but there is no entry for upload tmp directory.) Many thanks in advance. ...Rene -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Tricky variable syntax...
I'm trying to refer to a variable using $$, but with a twist. So far, this works: echo 'temp file: '.$$fld.'br'; In this case, $fld equals img_photo (although it could be anything). The above statement could have thus been echo 'file name: '.$img_photo.'br'; with the same results. So here I actually echo the value of the variable $img_photo. This is what I want. But here's my problem: echo 'file name: '.$$fld_name.'br'; What I want to do is echo the value of $img_photo_name. But how can I refer to it? Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Simple array question
Is there a simple way to return the key (name) of one element in an array? I looked up key() in the docs, but there are no examples or notes... Thanks. ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php