Jump to content

l008com

Members
  • Posts

    13
  • Joined

  • Last visited

About l008com

  • Birthday 04/28/1980

Profile Information

  • Gender
    Male
  • Location
    Stoneham, MA

l008com's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The LetsEncrypt root certificate expired on October 1st. I'm running one old server that does not contain this certificate. So I had to manually add it to the operating system so curl and web browsers could again communicate with domains that use LetsEncrypt SSL. It was pretty easy and hacks like that are to be expected when running a server thats a bit old. But PHP still isn't working. Using stream_context_create( ), I'm still unable to connect to LetsEncrypt certificates. So it would seem that PHP is not using the system's certificate roots. Does it have it's own collection of certs somewhere? If so, is there a way I can verify that, and then add the new LetsEncrypt one to it?
  2. I have a script that runs periodically by a launchd timer. I give the script a very tight timeout ( set_time_limit(120); ). Most of the time, my script works great. But every once in a while, one of the commands I run in an exec( ) call seems to hang. This of course is a problem because once the exec( ) call hangs, the php script hangs as time spent on exec( ) calls does not count towards the script's runtime. Furthermore since the script is still running, launchd doesn't call it again. So in this way, my script is entirely at the mercy of a command line program not having a problem. And if it does, I can't do anything about it. So while I could try to figure out why my particular command seems to go awry (which is its own weird issue), the bigger issue is how can I call command line programs in php in a way that don't allow a runaway command to lock up the whole script forever? I wish there was an exec( )-type function with timeout built in. Or even a script timelimit function that DID count pauses and external programs. Something to kill this!? Something other than a SECOND php script that would check on the first script and kill it when there is a problem. There MUST be a better solution than that? Any thoughts?
  3. So turns out the bindto IP needs to be in the format of x.x.x.x:0, so I changed my code a bit and now it's working properly: $options = array("socket" => array("bindto" => OPERATING_IP.":0" ));
  4. Wow this forum loves to eat half my post spontaneously. The REST of the post above said that OPERATING_IP is a user defined constant but it still doesn't work even if I hard code the IP address in there as a string. And yes I verified the IP is correct. And I also verified again that the socket_create( ) / socket_bind( ) code from above, DOES bind to the proper IP. This is the code that works but has no connection timeout. So any thoughts on why binding with stream_socket isn't working?
  5. So I got around to playing with this tonight. This new way of opening sockets does work. And the timeout does seem to work properly (although I do need to do some more thorough testing, but so far so good. HOWEVER it does not appear to be binding to the IP provided. This is what I have going on: $params = array('socket' => array('bindto' => OPERATING_IP)); $context = stream_context_create($params); $socket = @stream_socket_client("tcp://$ip:$port", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
  6. I'm having issues working with sockets in PHP, I'm hoping someone can help. I'm making an application in which I need to open my own socket connections. There are two specific features that I need: I need to set a timeout for the connection attempt. I need these connections to come from a custom IP address, and by that I mean that my server has more than one IP, and I need the socket connection to use an IP that is not the server's default internet connection port. There are (as far as I know) two ways to open a socket connection. Both techniques meet a requirement and miss a requirement. Option 1: I can use the function fsockopen( ) to open the connection. This function works great and let's me set a timeout for the connection itself. It's solid and reliable. However it has, as far as I can tell, no way to set the connection to come from a custom IP. All connections using this function come from the server's default IP address. Option 2: The socket_create( ) / socket_connect( ) family of functions. These functions have a lot more options, they let you do a lot more. I can easily bind the socket to my server's secondary IP address so socket connections will come from it. HOWEVER as far as I can tell, these family of functions lack a connection timeout. You can set timeout for reads and timeouts for writes. But there doesn't seem to be a way to set a timeout for initiating the connection itself. Even setting the "default_socket_timeout" parameter doesn't have any effect on the connection time. This type of question is a bit more technical than most PHP questions. But I'm hoping someone out there knows a way I can open sockets while meeting both of my two requirements. It's entirely possible that it is not possible, I know. But hopefully it can be done. One thought I had was a way of using the second option, and wrapping the whole socket_connect( ) function inside of another function that sets a timeout, and would kill the socket_connect( ) function once the timeout was met. However, I don't know of any such system in PHP, this was only a concept theory. How I open my sockets using fsockopen( ): $sock = @fsockopen($ip,$port,$errno,$errstr,$timeout); How I open my sockets using socket_create( ): ini_set("default_socket_timeout",$timeout); $sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); socket_bind($sock,OPERATING_IP); socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec" => $timeout, "usec" => 0)); socket_set_option($sock, SOL_SOCKET, SO_SNDTIMEO, array("sec" => $timeout, "usec" => 0)); $sock_status = @socket_connect($sock,$ip,$port);
  7. I've got a simple query that counts distinct items in a table SELECT COUNT(DISTINCT flag_rest_spam.msgid) FROM flag_rest_spam What I want to do is add a threshold to the count. What I mean is I want to count distinct items in the table, but i only want to count items that have more than N number of items. I'm not sure how to do this?
  8. PHP 5.2.3 I have no php.ini file. I'm running PHP with apache. I've looked through my phpinfo() and I haven't seen anything telling at all. If there are any specific values in that or my httpd.conf, let me know which ones and I'll look them up. Server-status is enabled, and use i used ps -U www | wc -l to count the apache processes. 160 may be a lot, but according to the documentation on my OS (10.3.9 Server), the limit is 1000 processes per user and 2048 total processes. I'm nowhere near that. And apache isn't being pinched, it can spawn more of itself as needed. Only PHP is getting pinched. Looking at server-status, I see 100 requests being processes, 76 idle servers. If there is anything specific in there that would be helpful, let me know and I can give you that info too.
  9. The scripts that I'm running system and exec on have nothing to do with the DoS. The DoS is on the home page. The exec and others are running on other pages that barely get any traffic it all. Last night I did some counting and was getting a steady 160±5 apache processes running and none of my scripts could run any external programs. If you have any ideas why this is happening and how I can change my settings so php is allowed to run external programs under what really is still a relatively light load, that would be helpful. Not criticizing my code that you haven't even seen.
  10. I have a new problem. PHP can no longer fork out external programs 95% of the time. This has been going on for the past week. You see, for the past week, I've been under a form of DoS attack on my server. Thousands of different users loading the same one page on one of my web sites, over and over. I'm averaging 200-300 page loads per second, with peaks upwards of 1200 per second. I was able to block these abusers, and now apache is sending them text only, super short 403 errors. Its working pretty good, percentage wise, my server's load is pretty low. The problem is, since this started apache can't run external programs. It least, usually it can't. Clearly these two events are related, but I don't see how. I checked and Mac OS X Server has a limit of 1000 process per user. Thats pretty high. Apache is configured to have only 450 simultaneous connection. Keepalive times out after only 2 seconds. Users 'www' should never even be able to get close to the user limit! Keep in mind that 99% of my traffic right now is abusers that are getting a short text '403' error and nothing else. No php, no cli programs, no mysql. Sever load is 20-30% usually, when I'm not in a spike. And my load averages often hover right around 1.00 or even drop below that. I can ssh into the machine and run anything I want. I have no idea what is causing these unable to fork errors. This is what I get when using exec( ) to try to display 'uptime' Warning: exec() [function.exec]: Unable to fork [uptime] in /Users/johnm/webfolder/webservices/uptime.php on line 1 This is what I get when I use backticks to run 'whois' Warning: shell_exec() [function.shell-exec]: Unable to execute 'whois phpfreaks.com' Again I know this problem is related to all this extra load my server is under, but I don't know how, and I don't know how to fix it. My server isn't under THAT much load, there must be a misconfigured setting somewhere? Something like that?
  11. So I recently decided I couldn't wait anymore, and I finally upgraded my server from PHP 4 something to PHP 5.2.3. I compiled PHP from source, with a bunch of custom things like imap mail libraries, mysql, zlib, mhash and more. Problem is apache doesn't want to start up now. I get the following: The first time I got this, while doing the installation, I ended up basically just turning off all virtual hosts and turning them all back on one by one. Thats not a very graceful solution. It has happened again, and while apache IS running now, it won't reboot, so I'm going to be out of luck. Does anyone know what the damn problem is with this? Its really annoying! This is Mac OS X Server 10.3.9 running Apache 1.3. I've compiled and recompile PHP 4.x.x for my server a million times and it worked great every time. But PHP 5 has been very odd, very problematic.
  12. Hello I'm making a php XML parser that loads data into mysql database. I'm using just the basic XML functions. The files I'm parsing are uber huge, so I can't use one of the easier XML parsing methods that load the whole file into memory. So anyway, I read a file line by line, and pass each line into the parse. I keep getting invalid character errors. I use the utf8_encode() function and it got a little further. I added a function to replace all &'s with &amps; (which apparently is a bug in the XML file, that this isn't already done) and it got a little further. But its still not making it nearly all the way through the file. This particular is 256 MB that I'm trying to parse, though once this is squared away, I'm going to have an even bigger one I want to build a parser for to run once a week. So what I really need, is a way to clean the xml data before giving it to the parser. With MySQL, i use the myql_real_escape_string() function before giving it data, and it works nicely. Is there any function or technique I can use to do the same kind of cleaning to lines of XML files? Even if it just deletes "illegal" characters? Here's my script, FYI. The XML file is a very simple format, its just very very long. <? set_time_limit(0); $insiderest = false; $tag = ""; $title = ""; $country = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $phone = ""; $url = ""; // Create an XML parser $xml_parser = xml_parser_create(); // Set the functions to handle opening and closing tags xml_set_element_handler($xml_parser, "startElement", "endElement"); // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, "characterData"); // Open the XML file for reading $fp = fopen("/path/to/zmlfile.txt","r") or die("Error opening xml file."); // Read the XML file one line at a time while ($data = fgets($fp,4096)) { //Clean String for XML parser $data = utf8_encode($data); $data = str_replace("&","&",$data); // Parse each line with the XML parser created above xml_parse($xml_parser, $data, feof($fp)) // Handle errors in parsing or die("XML error: ".xml_error_string(xml_get_error_code($xml_parser))."(".xml_get_error_code($xml_parser).") at line ".xml_get_current_line_number($xml_parser)."++$data++"); } // Close the XML file fclose($fp); // Free up memory used by the XML parser xml_parser_free($xml_parser); function startElement($parser, $tagName, $attrs) { global $insiderest, $tag; if ($insiderest) { $tag = $tagName; } elseif ($tagName == "RESTAURANT") { $insiderest = true; } } function characterData ($parser, $data) { global $insiderest, $tag, $title, $country, $address, $city, $state, $zip, $phone, $url; if ($insiderest) { switch ($tag) { case "D:TITLE": $title .= mysql_real_escape_string(trim($data)); break; case "COUNTRY": $country .= mysql_real_escape_string(trim($data)); break; case "ADDRESS": $address .= mysql_real_escape_string(trim($data)); break; case "CITY": $city .= mysql_real_escape_string(trim($data)); break; case "STATE": $state .= mysql_real_escape_string(trim($data)); break; case "ZIP": $zip .= mysql_real_escape_string(trim($data)); break; case "PHONE": $phone .= mysql_real_escape_string(trim($data)); break; case "URL": $url .= mysql_real_escape_string(trim($data)); break; } } } function endElement($parser, $tagName) { global $insiderest, $tag, $title, $country, $address, $city, $state, $zip, $phone, $url,$xml_parser; if ($tagName == "RESTAURANT") { $query = "INSERT INTO `chefmoz_list` (name,country,address,city,state,zip,phone,url) VALUES('$title','$country','$address','$city','$state','$zip','$phone','$url')"; mysql_query($query); echo "Insert restuarant `$title` into database [".mysql_insert_id()."]\n"; $insiderest = false; $title = ""; $country = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $phone = ""; $url = ""; } } ?>
×
×
  • Create New...

Important Information

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