Jump to content

justinh

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by justinh

  1. You're right. I forgot about the timeout in the case of the server being off. My experience is it takes 21s to return an error. I need to find a way for the head request to abort after so much time (less than 21s). Then that might work. It's not elegant, but it might serve the purpose.
  2. Checking for the header may work. Ajax is dependent on jQuery, correct? Is it possible to do the same thing with the native Fetch API? Would I have to check for a specific header property (like status) or if there is no header it would return false and I could just use that? The server is not always streaming. The server is running only when it is streaming.
  3. Yes, I've been using the browser's dev tools; that's how I discovered some of the findings above. The stream originate from my domain, it is not an arbitrary URL. JS can work, as described above, but it is just not reliable. BTW, I tried many event handlers, but I mentioned what I found to do something useful for me. The ended event would be useful when the stream is ends of course, either because it is at the end or because of a network interruption onerror also. But, the scenario is not that simple. The problem is whatever I use has to account for any situation, this it why it has to be like a monitor. The stream could be on or off any time (before or after the page is loaded, interrupted and recovered, etc.).
  4. I confirmed that event handlers don't continuously monitor changes. This is so frustrating. <audio id="myAudio" oncanplay="myTimer0()" onprogress="myTimer00()" onerror="myTimer000()" controls> If stream is on, upon page load onprogress fires. Stop the stream (at server). Reload the page and onprogress still fires. This is the same behavior as with the original methods - I have to clear the cache to get a true reading!
  5. Thanks. I found that onstalled fires if the stream is not available upon page load. It also appears that the audio tag starts looking for the source as soon as the page loads, instead of when the user hits play. Is that correct? That might explain the disconnect between me and justsomeguy 😟 Here's what I think to be the problem with theses events. the page loads - stream is not available, JS is used to show error on page 10 seconds later the stream becomes available (the sever is now sending a stream) Are the events going to be in effect now? Will the on oncanplay event now fire? If so, JS could now be used to show an updated status on the page
  6. Right, so what causes the download to start? Wouldn't the user have to hit play for the download to even start? (To be sure, audio will not start playing by itself, the user will have to initiate playback.) In my case, if the server opens a connection, there is data in the stream. (Can a stream actually have empty data??) Thanks, Ingolme. Your explanation of the event is better than MDN's.
  7. Well, I just want to know if the audio is available. It doesn't matter if it is playing (in my browser). It's like checking for a PNG file on the server; it doesn't have to be loaded on my page to be available for download, it just has to exist, so I can call it when I want it. The audio (if available) won't play until I hit play on the player. I'm sorry if I'm using non-standard verbiage, but it is the only way I know. Yes, canplay looks like it might be suitable. So, to use it, my code would look something like: var v = document.getElementsByTagName("audio")[0]; v.addEventListener("canplay", myfunction()); 1) When the page loads, this event handler will automatically start? 2) The event handler will, on it's own, just continue to check the event forever? For #2, this is my confusion. The audio could be available, but it doesn't push itself to the page, does it? If it doesn't, then how would the event be triggered? Upon page load, does the 'page' try to hook up to the stream or is it ignorant of the stream until I hit play? I do appreciate the help.
  8. No. I need to DETECT if the stream exists or not (is it available to play?). I don't care if the browser is actually playing it, that is not the issue. I'm not sure if any of the Media events will do what I need, because it looks like the user has to interact with the page at some time or another for any of the events to trigger. I'll have to try, after I figure out how to use event handlers. :-)
  9. Yes, active = stream is live (playing). But is there an event handler to detect when the stream is turned and turned off? Something equivalent to what I have now?
  10. I'm trying to check for an audio stream, to see if it is active. I found two methods, .networkState and .readyState, that work against an audio tag or an Audio() object. Things look okay when the stream is off and never been listened to (not in browser cache). I have both methods being executed every 4s to catch any change in the stream. The trouble is that I can't get either method to correctly update the status of the stream once it has changed, that is, from off to on or on to off. I have to refresh to the page to get a real update. Then, after you've listened to the stream and it is cached, it always shows as 'on'. (The counters are updating, so I know the page is updating, but the stream detection is not updating dynamically.) Why wouldn't the status change when the stream changes? Is there a way to force a check against the actual object instead of the cached object? (excuse my code - I quickly chunked this together and I am a newbie) (I went thru all the below to test the diff methods and for debugging, so you can look at only function to get the drift) <audio id="myAudio" controls> <source src="http://myserver.com:8080/live.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <!-- BEGINS: AUTO-GENERATED MUSES RADIO PLAYER CODE --> <script src="https://myserver.com/stream/mrp.js"></script> <script> MRP.insert({ 'url':'http://myserver.com:8080/live.mp3', [ . . .] }); </script> <!-- ENDS: AUTO-GENERATED MUSES RADIO PLAYER CODE --> <!-- this is what does not update correctly on the page --> <p>StreamN0 is: <span id="netstate">OFFLINE</span></p> <p>StreamN1 is: <span id="netstate1">OFFLINE</span></p> <p>StreamR0 is: <span id="readystate">OFFLINE</span></p> <p>StreamR1 is: <span id="readystate1">OFFLINE</span></p> <script> var myTimerVar = setInterval(myTimer, 4000); var myTimerVar1 = setInterval(myTimer1, 4000); var myFunctionVar = setInterval(myFunction, 4000); var myFunctionVar1 = setInterval(myFunction1, 4000); var aud = new Audio('http://myserver.com:8080/live.mp3'); var n0 = 0; var n1 = 0; var r0 = 0; var r1 = 0; function myTimer() { var acheck = document.getElementById("myAudio").networkState; if (acheck == 2) { //(acheck == 2 || acheck == 3) document.getElementById("netstate").innerHTML = "buffering " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "yellow"; } else if (acheck == 3) { document.getElementById("netstate").innerHTML = "OFFLINE " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "yellow"; } else if (acheck == 1) { // works in local env but says online when on server; not reliable document.getElementById("netstate").innerHTML = "ONLINE " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("netstate").innerHTML = "unknown " + acheck + " - " + n0++; } } function myTimer1() { var acheck1 = aud.networkState; if (acheck1 == 2) { document.getElementById("netstate1").innerHTML = "buffering " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "yellow"; } else if (acheck1 == 3) { document.getElementById("netstate1").innerHTML = "OFFLINE " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "yellow"; } else if (acheck1 == 1) { document.getElementById("netstate1").innerHTML = "ONLINE " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("netstate1").innerHTML = "unknown " + acheck1 + " - " + n1++; } } function myFunction() { var x = document.getElementById("myAudio").readyState; if (x == 0) { document.getElementById("readystate").innerHTML = "OFFLINE " + x + " - " + r0++; document.getElementById("readystate").style.backgroundColor = "yellow"; } else if (x == 4) { document.getElementById("readystate").innerHTML = "ONLINE " + x + " - " + r0++; document.getElementById("readystate").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("readystate").innerHTML = "unknown " + x + " - " + r0++; } } function myFunction1() { var x1 = aud.readyState; if (x1 == 0) { document.getElementById("readystate1").innerHTML = "OFFLINE " + x1 + " - " + r1++; document.getElementById("readystate1").style.backgroundColor = "yellow"; } else if (x1 == 4) { document.getElementById("readystate1").innerHTML = "ONLINE " + x1 + " - " + r1++; document.getElementById("readystate1").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("readystate1").innerHTML = "unknown " + x1 + " - " + r1++; } } </script> I'd appreciate any help.
  11. Is it possible to change/modify a loaded web page automatically with PHP? I want to load a page, then have PHP do something, then update the page with the new information (like change a text string).
  12. justinh

    header info query

    EDIT: I found a config modules dialog in UniServer where I could toggle on php_openSSL.dll, and that enabled the HTTPS stream. Now I get success in my local env! Without this config interface I don't know how this would be configured (or why it is not out-of-the-box) - - - - I tried running my PHP file on my local stack (WAMP, Uniform Server Zero). I was getting a bunch of errors. php.ini shows allow_url_fopen = on. I was testing with HTTPS URLs, and I finally discovered that my local PHP does not have the HTTPS stream registered, but my remote PHP does have it registered. I can't figure out what is controlling the registration of streams or how to add a stream. Anyone know? Warning: get_headers(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar PS Sorry, dsonesuk, I was getting .htaccess and httpd.conf confused. Thanks.
  13. justinh

    header info query

    It appears my setting for "allow_url_fopen" in my file's folder php.ini was not being honored; it wouldn't work even if I set it in the PHP file, even if I set the X-frame-options header. I had to set "allow_url_fopen" in the site root's php.ini! I thought the local (to the file) php.ini would be in effect. Is there someway to make that work, or am I totally washed up about that? Maybe I am thinking about htaccess? Man, I fought this for two days! Thanks so much, everyone. I'm sure I'll be back after I get to the next step :-)
  14. justinh

    header info query

    Var_dump of the get_headers is showing " bool(false) ". Why would it be false? What I found out about file_get_contents is that it works with relative paths (e.g., '../myfile.txt') but not with an absolute path (e.g., 'https://myserver.com/myfile.txt'). I this same problem with getimagesize, file_exists, and fopen (though PHP.net shows an example with absolute path). Why won't absolute paths work on my server when supposedly they are supposed to work with these functions? I can't use relative paths because the file I'm checking for is on a subdomain that is on another server. And I can't rely on response headers, so I really like the idea of just checking for a file.
  15. justinh

    header info query

    Hi, I've been trying to get response header information and some PHP functions are not returning anything. I'm sure I am missing something fundamental, but I don't know why I'm not getting anything after I browse to header.php (which contains all of the below) on my remote server. From https://secure.php.net/manual/en/function.get-headers.php, example 1: $url = 'https://yahoo.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); It shows nothing on the page. From https://php.net/manual/en/function.get-headers.php#97684: function get_http_response_code($theURL) { //https://php.net/manual/en/function.get-headers.php#97684 $headers = get_headers($theURL); return substr($headers[0], 9, 3); } echo get_http_response_code("https://yahoo.com"); It shows nothing on the page. From https://php.net/manual/en/function.get-headers.php#112652: function get_http_response_code($theURL) { $headers = get_headers($theURL); return substr($headers[0], 9, 3); } if(intval(get_http_response_code('filename.jpg')) < 400){ echo "file was found"; } else { echo "no file found"; } It shows nothing on the page. From https://secure.php.net/reserved.variables.server, example 1: echo ($_SERVER["yahoo.com"]); It shows nothing on the page. From https://secure.php.net/manual/en/reserved.variables.httpresponseheader.php: function get_contents() { file_get_contents("https://berean-biblechurch.org/rss/rss.xml"); var_dump($http_response_header); } get_contents(); var_dump($http_response_header); It shows "NULL". I'd appreciate any help. Justin
  16. I have a bit of a mystery with quotes in variables. I'm writing an application that takes a text string from a page from via POST, and I was concerned about dealing with single or double quotes. I know that if you use single to wrap the content, then there is no issue processing double: $myvar = 'I say "hello" world'; // I say "hello" world And if you use double to wrap the content, then there is no issue processing single: $myvar = "I say don't do that"; // I say don't do that If you use the same quote inside and outside w/o escaping the non-wrapping quotes, PHP will throw an error. Example: $myvar = "I say "hello" world"; // => Parse error So, I expected my POST values to give me errors if I didn't escape or convert to HTML codes, but I thought how can I do either to prevent an error w/o first incurring the error while extracting the POST data? I just tried using both quotes in my strings and everything works fine. $desc1 = ($_POST["desc1"]); echo $desc1; // this is double "test" and single 'test' string Even if I quote the variable in the echo it works. Why do I not get an error when going thru the POST? Justin
  17. Thank you so much - I understand it now after finally putting all the pieces together. I also figured out (from the link you provided) that the pattern string has to be enclosed by a delimiter, thus the two "/". Then the ending "i" mean case-insensitive alpha match. Just for anyone else that reads this post... It looks to me like someone could specialize just in regex coding! Thanks again.
  18. Okay, I'll need a much greater breakdown that that... First, how to understand the value for $pattern. Then, where is the second matched pattern? (it looks like we are missing one) Then, why are there no spaces in the output string? It just looks way too complicated to replace only the day, as it looks like it is matching the entire string and carrying forward some of the original string instead of just what needs to be replaced.
  19. I'm looking at this page about preg_replace: http://php.net/manual/en/function.preg-replace.php Which gives this example: <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?> The above example will output: April1,2003 I don't understand the transformation, how they go the answer. Can someone explain? Thanks, Justin
  20. Thanks all. I've tried some of these ideas - good to know stuff!
  21. Great info, dsonesuk! Now, can you give some details to help me understand better. Correct, the text is stacked in source. However, where else can I render PHP output besides a web page? I guess a file or a dialog box? So, is the bottom line that, if I am outputting to a web page, no need to bother with n, just use <br>? I guess I'm in rebellion a bit, because I want to use 'php' code in my PHP code and not HTML in my PHP code Thanks much! (yes, I'm a new newbie...)
  22. I'm using UniServer Zero XI with PHP Version 5.4.42 (on Win7). I've tried different ways to force a new line in the web page, like with n. Only HTML BR tag seems to work. Here is an exmple: <!DOCTYPE html><html><body><?phpfunction makecoffee($type = "cappuccino"){ return "Making a cup of $type.n";}echo makecoffee();echo makecoffee(null);echo makecoffee("espresso");?></body><html> Output is: Making a cup of cappuccino. Making a cup of . Making a cup of espresso. But should be: Making a cup of cappuccino. Making a cup of . Making a cup of espresso. Is this a server configuration issue? Appreciate the input, Justin
  23. I fixed it by adding this to the beginning of the while loop: unset($query_vars['unwanted value']);
  24. Hi, I have a server-side PHP script to enumerate all the values in a form submission. After these values are processed, they are pushed to another script for another purpose. Some name/value pairs are required for secondary processing and some I don't care about. I want to know how to remove the names I don't care about for the secondary processing. Here is the code: <?php $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET") { $query_vars = $_GET; } elseif ($request_method == "POST") { $query_vars = $_POST; } reset($query_vars); $t = date("U"); $file = $_SERVER['DOCUMENT_ROOT'] . "ssfmgdform_" . $t; $fp = fopen($file,"w"); while (list ($key, $val) = each ($query_vars)) { fputs($fp,"<GDFORM_VARIABLE NAME=$key START>rn"); fputs($fp,"$valrn"); fputs($fp,"<GDFORM_VARIABLE NAME=$key END>rn"); if ($key == "redirect") { $landing_page = $val; } } fclose($fp); if ($landing_page != "") { header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); }?> So, if I know the name ($key) I'm interested in, can I inject something like 'if $key="XYZ", skip it' so it doesn't get processed downstream? By the time I get to this point, there is a name I don't need and don't want to process. I can barely walk around in this code, so I need to be spoon fed a bit. :-) Thanks, Justin
  25. Yes, I have to use the PHP script. I see other pages with PHP (I'm pretty sure) form validation that will give user feedback on the page (showing red text and such) with no apparent page transition - it looks like real-time validation. How do they do that? Is the page actually being refreshed and I just can't tell it?
×
×
  • Create New...