Jump to content

soadlink

Members
  • Posts

    50
  • Joined

  • Last visited

    Never

Everything posted by soadlink

  1. Nevermind, I think I got it working by using jQuery.get from the jQuery library function processlist(list){ var splitlist=list.split("\n"); for ( var i in splitlist ){ var finalurl="phpscript.php?currentlistitem="+splitlist[i]; jQuery.get(finalurl, function(sreply){ document.getElementById("ServerResponse").innerHTML=document.getElementById("ServerResponse").innerHTML+sreply+"<br>"; } ); } } And it's asynchronous, so that's nice
  2. Here is a basic look at what I'm trying to do: - User enters data into a textarea box as a list and submits it - Javascript code splits the list into an array by the line break "\n". - Javascript code makes a GET request to a php script for each item in the array (depending upon what the item is). - The php script returns data. I want the replies from the php script to be displayed on the page as they are received (live!). By changing my code, it will either show all the replies AFTER they have all been received...or it will only send/receive a reply for the last item in the list. You might ask why I don't just process the list all at once instead of using a GET for every item in the list. The reason is that I wan't things to look good for the user. When they submit the data, I want them to be able to watch the replies for each item as they are received (assuming this is possible) instead of waiting until they are all done. Below is my code. You may notice in ajax.js that the GET request is false (synchronous). This was the only way I could get it to process all items in the list. If I set this to true, it would only process the last item. Thanks in advance <?php $currentlistitem = $_GET["currentlistitem"]; echo $currentlistitem; sleep(1); ?> <html> <head> <script type="text/javascript" src="ajax.js"></script> </head> <body> <form> <textarea id="ta1" rows="15" cols="30" name="ta1"></textarea> <br/><br/> <input id="submit" type="button" name="submit" value="Submit" onclick="processlist(document.getElementById('ta1').value)"> </form> <b><label>Response: </label></b><br/> <div id="ServerResponse"></div> </body> </html> var xmlhttp; function processlist(list){ xmlhttp=GetXmlHttpObject(); if (xmlhttp==null){ alert ("Browser does not support HTTP Request"); return; } var splitlist=list.split("\n"); for ( var i in splitlist ){ var url="phpscript.php?currentlistitem="; var currentlistitem=splitlist[i]; finalurl=url+currentlistitem; xmlhttp.onreadystatechange=statechanged; xmlhttp.open("GET",finalurl,false); xmlhttp.send(null); } } function statechanged(){ if (xmlhttp.readyState==4){ document.getElementById("ServerResponse").innerHTML=document.getElementById("ServerResponse").innerHTML+xmlhttp.responseText+"<br>"; } } function GetXmlHttpObject(){ if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject){ // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }
  3. Interesting, might be a typo. I would agree that it sounds like they are talking about the destination port ???. I'll make a bug report and let them know just in case, but the bugs site seems to be down at the moment. Another good piece of info for socket_bind: use 0 in the source address field if you don't want to look up your machine's IP, and 0 in the port field for a random port.
  4. Yea, I just tested it and it worked. What you're referring to is the socket_connect function (that is where you specify the dest ip/port). The socket_bind function allows you to bind your particular socket to an address/port belonging to your machine before the connection is made. Here is working code: <?php $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_bind($socket, "192.168.1.2", "45456"); socket_connect($socket, $remoteip, $remoteport); socket_write($socket, "Hello World"); ?> So 192.168.1.2 has to be an ip belonging to my machine (or you get the error: Cannot assign requested address) , and I would assume 45456 would have to be unused by any other processes (you would most likely get another error). Going to mark this topic as solved, as socket_create seems to be a working solution (though not as easy as I assumed it would be ). Feel free to keep posting though if you guys wan't to continue the discussion, but I think I can manage to work this into my script from here. Thanks
  5. I'm just using the CLI for this particular script, so no apache is involved. But I think you are correct in referring to using exec to call on netstat or something similar (and then just parse the info). I was hoping there was an easier way though . I did a little more reading, and I see that I can create a socket (socket_create), bind it to an address/port (socket_bind), and then have set it send out the data on that socket. And I know the source port because I can specify it during socket_bind. A little more code, but I think it would work. I'll try this, and also play with the netstat parsing, but if anyone has any other ideas feel free to post them. Thanks
  6. Hello, If I create a udp socket, and send data on it like so: <?php $socket = fsockopen("udp://" . $ip, $port); fwrite($socket, "hello"); ?> ... is it possible to see the source port that the socket has bound itself to for the sending of data? I know I can packet scan or use something within the OS itself, but I'm looking for a way to store this source port as a string (within the script itself), and use it for whatever I need. I did some searching but wasn't able to find anything; however, it seems like it's probably very simple . Thanks!
  7. I really need to search harder: rtrim() The rest works as I want it to now
  8. Hello, I am working with processing large lists of words (over 10mb for some!), and they have 1 word or string on each line. I WAS using a different method, but it was eating up my memory because it would load the entire list into memory, so I was forced to take a different approach. I'm using command line for this. Here is my attempt: <?php $file = 'largelist.txt'; $handle = @fopen($file, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle); echo md5($buffer) . "\n"; } fclose($handle); } ?> So the code should echo the md5 hash for each list item on a new line, but the problem is that the MD5s are not the correct when it does. Only the very last md5 processed in the list is correct. I believe this may have to do with hidden line breaks being inserted. I would like to be able to decide when line breaks are used. So basically what I am looking for is: to be able to process each word in the list as I wish, but only the word! Not anything else like line breaks or hidden chars; I choose when the line breaks \n come in if I need them! Also, it would be nice to use the same variable each time around in the loop for the current word in the list (i.e. in my example I was able to use $buffer for each list item). This is probably a given though. Thanks, and if I confused anyone let me know, and I'll try to explain it better
  9. Did you forget to put the ?> at the end of your code?
  10. Yea it is doing stuff with the words on each line, I just had it stripped down (just echoing) for easier understanding. I guess I don't need an array, and could look at alternative methods for loading large lists and processing them. I was just hoping there was an option I could change so it doesn't load the entire list into memory as it appears to be doing, like Windows appears to do correctly. I'll try the solution in that link you gave and see how it works, thanks! MemTotal: 1035672 kB MemFree: 118592 kB Buffers: 177008 kB Cached: 576840 kB SwapCached: 0 kB Active: 626848 kB Inactive: 240496 kB HighTotal: 131008 kB HighFree: 592 kB LowTotal: 904664 kB LowFree: 118000 kB SwapTotal: 3028212 kB SwapFree: 3028212 kB Dirty: 180 kB Writeback: 0 kB Mapped: 154300 kB Slab: 39084 kB CommitLimit: 3546048 kB Committed_AS: 467732 kB PageTables: 1748 kB VmallocTotal: 114680 kB VmallocUsed: 5724 kB VmallocChunk: 108700 kB
  11. Hello, I am working with the following script that loads a list into an array and then echos each word in the array on a new line: <?php $loadlist = array_map("rtrim", file("c:\\list.txt")); foreach ($loadlist as $word) { echo ($word . "\n"); } ?> I run my scripts with the CLI (not on a website), and it works great in Windows XP when loading lists as large as 375,000 words, and I can run plenty of instances of it without lag issues (8+ command lines going at once). But when I try to run the same script on Ubuntu I get the following error: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 13491373 bytes). But that can easily be fixed by setting a larger memory limit such as: ini_set("memory_limit","75M"); However I only have to up the memory limit on Ubuntu, but not Windows. And when I do up the memory limit on Ubuntu, only 1 or 2 instances can be run before the machine starts to bog down and get really slow. I'd assume this is because php is trying to load the entire list into memory in Ubuntu, but I am curious as to why Windows runs it fine. The PCs are the same (I just removed the Windows install recently and put Ubuntu on there), and it has 1GB of ram, and an AMD64 3200+ processor. I'm just wondering if there is something I need to change to get the script to run like it did Windows, without being a memory hog or having to increase the memory limit (since I didnt have to on Windows). Thanks for the help
  12. For the UDP protocol? I didn't think it used SYNs because it doesn't care about arrival, ordering, etc. It just sends it out (connectionless).
  13. What would be the easiest/quickest way to spoof the source address of a UDP packet so it appears to be coming from somewhere else? Or if it was just possible to have an optional field for it like so: $socket = fsockopen("udp://" . 'destinationip', 'destinationport', 'sourceip', 'sourceport', $err, $str, 10); Probably wont be easy, but I just thought I'd ask to see if anyone knows a way if it's even feasible. Also, I already tried posting in the core php hacking since I didn't find a way to do this with normal functions, but I was told it's the wrong thread, so here I am.
  14. Because the information is not stored in a database, its stored in an .rtf file.
  15. Hello, I have a script that does some logging to a .rtf file, and in the logs it adds timestamps and creates a new line "\n". So I end up with a bunch of lines like so: word1 (Sun Feb 11th, 2007 04:45 am) word2 (Sun Feb 11th, 2007 04:46 am) word3 (Sun Feb 11th, 2007 04:47 am) word4 (Sun Feb 11th, 2007 04:48 am) I realized now that for what I'm doing this wasn't a very good idea to log the timestamps because they aren't important, and need to remove the timestamps. There are hundreds of lines per log, and many logs, so editing it manually would take a long time. The days, dates, times, etc.. are all different and are not in any order like in my example. I am looking for a way to load the log file as an array, and remove all the timestamps, and output the result as a new array. So for my example the new array would be: word1 word2 word3 word4 If there is a way to remove the everything in between the (), that would work too because none of the 'words' will have () in them, so there would be no conflicts. Or if you guys know a quicker way than using a php script let me know Thanks for the help!
  16. Sorry, I jumped ahead of myself. I realized, it's the same speed. Its just using different variables for each socket each time around, but not actually connecting to multiple sockets at once. Maybe it would work out if it split the array of words into chunks of X, and then connect to all those sockets at once, and then loop it around and do the next chunk of words. That way we are connecting to X sockets at once, and X can be whatever I specify. But yes sorry I jumped ahead because we were only working with the initial connect (which is fast). When you add in my code to it, its same speed as my original.
  17. Wow works great, much faster too. Thanks a lot.
  18. Because the server I am working with closes the socket at a certain point in my script. This is just a stripped down version of it. You have to open new sockets for each word, I'm just looking for a way to get more sockets open at 1 time.
  19. Hello, I'm wondering if it's possible to have multiple open socket connections at a single time within a loop, and have them each echo a "conected" or "timed out message" on a new line as they get them. The script would be connecting to the same server:port. I would like to work this into this script that utilizes only 1 socket at a time: <?php //Path to list $filepath_to_list = 'c:\\list.txt'; // Load the list of words $loadlist = array_map('rtrim',file($filepath_to_list)); // Start the loop foreach ($loadlist as $words) { $socket = @fsockopen('gpcm.gamespy.com', 29900, $errno, $errstr, 5); if (!$socket) { echo 'Sorry it timed out after 5 seconds. Skipping the current word' . "\n"; fclose($socket); } else { echo "I connected just fine." . "\n"; } } ?> You will notice that list.txt is loaded as an array, and for each word in that list a connection to a new socket is created. Well if it is waiting for each socket to get done, that could take a while. So it would be nice to set a number of simultaneous sockets that can be used at once, to make the script work faster. I would prefer this, rather than having to open multiple instances of the script.
  20. I like the site idea and design. A simple design, and and it goes great with the idea of the site. Many people would take the idea of php snippets and clutter the site with un-needed junk (for example signing up to do stuff, or un-needed features, or ads :-X)... and just stuff to make the browsing unpleasant. Your site is fast and simple, yet effective. And I am also going to use the php captcha in a project of my own
  21. You may want to look into something like a portal, and then strip down the code. I use a stripped down version of phpBB Fetch All (http://www.phpbbfetchall.com/) for my site, however I don't think the creator supports it anymore. But it still works great for me in 2.0.22.
  22. Nevermind, the problem was when I was physically unplugging the cable from my switch. Windows would release my IP since there was no connection... and php would go nuts because there is no connection. But when I pulled my modem offline (which was not affecting my local IP at all), the timeouts work perfectly because it appears there was just a problem up ahead, but I still had my IP leased to me in windows. Anyways...is there a way to check for an active internet connection in windows, or a local IP... or something before continuing... so php doesn't go nuts like this again?
  23. Hello, I am working on a script that is having problems using the timeout feature for fsockopen. I want it to work well in the event that there is a connection error. The generic script I have provided loads a LONG list of words (1 word per line), and then connects to a server for every instance of the word. After connecting, it simply echos I connected just fine and moves on to the next word to try and connect again to this same server. But if the socket timed out when connecting to the server (which I have set to 5 seconds), I want it to echo Sorry it timed out. Skipping the current word and then skip the word in the list... and do another fresh connection attempt on the next word in the list. My script does it's job for the most part, except when I physically pull the plug to test the timeout feature. It will usually sit there............. and then finally echo that it timed out.... but then right after that it will keep echoing that message REPEATEDLY without waiting another 5 seconds. It's like the script is not even trying to connect again. It just floods the console with the echo until it is done going through the words. It should wait 5 seconds for EACH attempt, and actually keep trying to make a connection attempt. And if it fails, just skip the word and move on to the next word... waiting 5 seconds again if needed.. If you try the script out on your own machine and pull the plug, you will see it detects the timeout ok... but then floods the console with the timeout message until the list is done. If the list is long enough, and you plug the cable back in while it's still flooding, the script will resume as normal once the machine gets back online. <?php //Path to list $filepath_to_list = 'c:\\list.txt'; // Load the list of passwords $loadlist = array_map('rtrim',file($filepath_to_list)); // Start the loop foreach ($loadlist as $words) { $socket = @fsockopen('gpcm.gamespy.com', 29900, $errno, $errstr, 5); if (!$socket) { echo 'Sorry it timed out. Skipping the current word' . "\n"; fclose($socket); } else { echo "I connected just fine." . "\n"; } } ?> Also, I have the @ because on timeout it generates a warning which I'd prefer to hide. Didn't now of a better way to catch this, and would just rather have my own echo warning.
  24. Wow thank you very much, it was my linksys router causing the problem. 8) I was also suspecting this since: - Multiple languages I've worked with freeze, not just PHP - It worked on my webserver (they're running higher end gear that's not stopping my connections, and linux) - Last night before bed I tried 1 instance running on each of my pcs (to see if it was the connection, or the pcs), and they both paused. So it didn't seem to be a pc deal - I've worked with this and had the sockets connecting on port 80 to a webserver, and it worked, but probably because the router is lenient with that port. I just never physically removed the router and directly connected to test it :-\. So I directly connected to my cable modem and opened 5 instances of the script, and it ran perfectly. So I will have to tink around with this router . It's a WRT54GX (I use the wired portion though, not wireless). Anything you recommend I check/change in this router? Only think I can see is the Enable or disable the SPI firewall.. The rest of the settings are port forwarding settings/wireless settings (which I have disabled at the moment)/isp settings/etc.. and don't look like they would affect my issue. Or if you can recommend a good SOHO router that isn't so picky But anyways thanks again guys for the help, this makes me sort of like VB again (since it wasn't ever VBs fault)
×
×
  • 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.