Jump to content

soadlink

Members
  • Posts

    50
  • Joined

  • Last visited

    Never

About soadlink

  • Birthday 09/05/1987

Profile Information

  • Gender
    Male

soadlink's Achievements

Member

Member (2/5)

0

Reputation

  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.
×
×
  • 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.