Jump to content

RuleBritannia

Members
  • Posts

    92
  • Joined

  • Last visited

Everything posted by RuleBritannia

  1. Hello I want to get a count of how many needles are found. Im aware there are some different ways to search a result with 1 needle, But If I have an array of needles $result = 'fgnfmgn NEED this 22 STRING dgfdfsgfdgfd NEEDS 55'; $needle[0] = 'NEED this 22 STRING'; $needle[1] = 'NEEDS 55'; Most functions like substr_count and preg_match_all, will work for 1 needle as a string, but wont accept more than one needle in the form of a array. What do you think is the best way to achieve this? I'm thinking foreach loop with substr_count, But wanted to ask here encase there is a simpler way of achieving this. Thanks in advance.
  2. Managed to get a answer on the official ffmpeg boards to those interested, You can use the query -select_streams v Then do your other stuff with the returned result.
  3. Hello It seems google has failed me with this one. I need to show specific entries in the output, which I am able to do with -show_entries command. my query "-show_entries stream=index" This is fine, and it will return 4 of the indexs inside the streams wrapper. The problem is, I actually need width,height, Which I can do like "-show_entries stream=width,height" Inside each of these 4 streams wrappers, only 1(set as index 1) contains width and height, But in the result output, it will actually return all 4 wrappers, 3 with blank info, and 1 with the width and height settings. Does anybody know a way to specifically just target index 1, I have tried numerous different commands now, And cant see to get it, the documentation shows the following. ‘-show_entries section_entries’ Set list of entries to show. Entries are specified according to the following syntax. section_entries contains a list of section entries separated by :. Each section entry is composed by a section name (or unique name), optionally followed by a list of entries local to that section, separated by ,. If section name is specified but is followed by no =, all entries are printed to output, together with all the contained sections. Otherwise only the entries specified in the local section entries list are printed. In particular, if = is specified but the list of local entries is empty, then no entries will be shown for that section. Note that the order of specification of the local section entries is not honored in the output, and the usual display order will be retained. The formal syntax is given by: LOCAL_SECTION_ENTRIES ::= SECTION_ENTRY_NAME[,LOCAL_SECTION_ENTRIES] SECTION_ENTRY ::= SECTION_NAME[=[LOCAL_SECTION_ENTRIES]] SECTION_ENTRIES ::= SECTION_ENTRY[:SECTION_ENTRIES] http://www.ffmpeg.org/ffprobe.html#Main-options Thanks in advance.
  4. Its better you post the upload part of the code in the post, so people dont have to download files and unzip etc.
  5. Ok So I did manage to find a core function to do this For those interested, array_column is the function. In what I was trying to acheive here, We can use it like this. <?php Array ( [0] => Array ( [id] => 40000 [type] => automatic [status] => error [colour] => o ) [1] => Array ( [id] => 50000 [type] => automatic [status] => good [colour] => e ) ) $status = array_column($array,'status'); //returns [0] = error [1] = good ?> With this result in a nice array, we can just use another simple function like in_array to test if the array contains a error string. I believe this is a much more elegant and simple way than to use big created functions or loops. EDIT, 1 last thought. If anybody has any other alternatives, please post, I have also found another, but its not so elegant as it consists of using 5 functions chained, But there is proberly even more ways to acheive this result. Thanks
  6. Thanks for the function below, But I will continue trying for a while as I believe there maybe someway of acheiving this. As for building something to be extensible, I want to make my code as lightweight(resourcefully and both lines of code) as possible
  7. Hello If I have a multidimensional array <?php Array ( [0] => Array ( [id] => 40000 [type] => automatic [status] => error [colour] => o ) [1] => Array ( [id] => 50000 [type] => automatic [status] => good [colour] => e ) ) ?> I want to search for the status 'error', and if it exists within the array, return true(thats it(dont need keys and such to locate it)) I am fully aware I can just make a loop, But I want to know if its possible using a core function. I have tried continuosly using functions like array_search, in_array, array_keys,array_values, And I cannot acheive it, But I am sure its possible. Thanks in advance.
  8. Ok im researching cli php now. Also it seems the partial fix I posted earlier doesnt even work 100% of the time, F*!@~# For now I have to progress, So I am using a different Pikey fix, for those interested, set curl_setopt($ch,CURLOPT_TIMEOUT,1); in the main script. This will not allow CURL to spend its time waiting on a page to execute, Incase anybody is wondering why its a bad fix, well thats because if there is a connection delay, CURL may not even have time to send the initial request.
  9. I havnt done any CLI php since last week, but I am moving in that direction as it seems more appropriate than to keep using CURL and some meta refresh as a cron service. In regards to your function, That looks very heavy, Is that the "normal" way of getting parameters from a php cli request? the comparison of $_GET['id'] to your function is a big markup diff
  10. I managed to find one possible method, but once again do not like it as it is a cheap workaround to replicate, I would rather get the exact effect, But here is goes to those interested. If you set header('Location : http://google.com'); in your run.php file And in the main curl script, set curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0); This manages to get the curl to stop executing once page loading finished, Whilst allowing further execution in the requested page.
  11. Hello I am using a curl script, to call another url(with get variable) on my server. Inside this url it calls, I have some code which takes a long time to execute, So to avoid script hanging I used Header: close, with some ob_flush functions etc, This allows the browser to close connection, but in the background it still proccess, the PHP. When i visit this URL with a get variable manually in the browser, this works lovely, The script imediatly stops loading, but in the background code is being executed. Now, When I use CURL in my main script to call this url(with get variables), CURL just likes to take its time and wait for everything to finish, causing my main script to hang. main.php <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://localhost/run.php?id=44'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); var_dump($result); ?> run.php <?php if(isset($_GET['id'])) { ob_end_clean(); header('Content-Encoding: none'); ob_start(); echo 'Closing'; $size = ob_get_length(); header('Content-Length: ' . $size); header('Connection: close'); ob_end_flush(); ob_flush(); flush(); ob_end_clean(); //Normally this sleep would cause the script to hang for however long specified. sleep($_GET['id']); } ?> This is a simple working enviroment, Call run.php?id=20 direct, You will see it loads very fast,(correct), then use main to call run.php?id=20, you will see it waits 20 seconds for sleep to finish. Hopefully somebody has experience with this. Thanks in advance.
  12. to those who maybe interested. I decided to take a differnt approach, instead of reading from a log file, I decided to wait for the process(let php hang) to finish and output results to a variable, then test for errors or success information, This way seems more reliable than checking for logs etc, too many problems can arise from this. Thanks
  13. Cant remember specifically without cmd, but it was definatly appearing with my cmd /C ffmpeg......... commands, And i could not hide it. after all of these differnet methods and so on, i finally just went with shell_exec in a external php script, then called it via curl and timeout 1(to ignore result info) I guess I still learnt alot from this, but it has gave me a big headache, and caused me to change the script so many times. Thansk for all your input
  14. 1. I have tested and it works, I just wrote this thread before implementing my theory, Assumed it would work because it wasnt very complex. 2. yes This approach works, But cant be the best way.
  15. Hello, I come accross this problem and im wondering how you may solve it. I believe I have one workign way but it might not be the best. So I am executing ffmpeg though php, and directing STDERR STDOUT to a log file, my php will run this without waiting for results. After the execution instance has been sent, I will check the log file to get some information directly after, The problem is, The log file has not yet been created, So it will not exist. Currently, I thought to call a loop allowing for a maximum of 10 seconds to pass checking each for log existence each second, If after 10 seconds there is still no log, assume error. Example just for theory purposes(not tested) $start = 1; $finish = 10; while($start <= $finish) { if($file_get_contents($log)) { $result = file_get_contents($log); $finish = 10; } sleep(1); $start++; } Im assuming this may work, But there maybe a better way to acheive this, How would you do it? Thanks
  16. Hello Yes, i already managed to get PID with this before I moved onto proc_open, The problem with this is you cannot hide the command window if I remember correctly.. Which I had to do, proc_open hides it, but permenantly, so its the opposite. Unless I dont know the full funcionality but I researched and tested alot.
  17. Sorry. Cannot edit, But 1 other alternative if others are interested http://stackoverflow.com/questions/5367261/php-exec-as-background-process-windows-wampserver-environment seems only way to do this in the background + without application windows opening is with popen or proc_open All else its impossible to get Process ID without application window opening.
  18. For those who it may concern, Some more info here. http://stackoverflow.com/questions/13289595/starting-a-windows-process-in-php-and-get-its-pid This guy had the exact same issue, seems its not possible, but a work around he posted. Thanks
  19. Pffft. Doesnt seem like this is possible with Run.
  20. You could use the serialize and unserialize functions So you have example $ProcessA = [0] = 'Green'; [1] = 'Red'; serialize($ProcessA) then insert into the database. Once serialized it wont be very readable looking directly at the table from phpmyadmin or other DB GUI's But then you would unserialize it and do whatever with...
  21. Its funny you say that, Because everywhere I am looking online regarding running processes in the background, Seem to use linux examples. still researching
  22. So here is one possible solution to get the ProcessID, But involves using $com->Exec instead of $com->Run And the problem with this is you can not supply much parameters(such as hide window, or hang php until command finish)etc. $com = new COM('WScript.Shell'); $d = $com->Exec('cmd /C C:\ffmpeg -y -i "C:\2.avi" -preset slow -crf 25 "C:\2.mkv"); echo $d->ProcessID When this runs, It will open up a command window, But actually shows nothing interesting whatsoever, then when its complete it will auto close. Using the Run property, If you tell it to open a command window, It will show all interesting information such as ffmpeg information etc, So I am still interested to find a possible solution using Run, I will research more and get back here. Thanks
  23. I am running a process, Via COM class and Run method, However to get the ProcessID seems impossible. $com = new COM('WScript.Shell'); $d = $com->Run('cmd /C C:\ffmpeg -y -i "C:\2.avi" -preset slow -crf 25 "C:\2.mkv" 1>C:\output.log 2>C:\error.log',0,false); I believe there is a property called ProcessID from my research I have tried var_dump($com->ProcessID); Error : Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `ProcessID': Unknown name. also tried var_dump($d->ProcessID); Error : Notice: Trying to get property of non-object in Im assuming the main place to get this would be from where it starts ($com), But as you can see doesnt work. When I var_dump($com) it shows just that its a object. var_dump($com) Result : object(com)#2 (0) {} Is this even possible to do? Thanks in advance EDITED while I can I forgot to mention, I am also reading about $com->Exec instead of $com->Run to see if there is a possiblity there, But would rather use run and find the answer to get ProcessID from that, But so far not possible from my research.
  24. For those interested I managed to find a way to get the ouput or error etc. Instead of just $com->Run('$command', 0, false); Use $com->Run('cmd /C $command', 0, false); It still maybe possible to do in the first, but I couldnt get it to work after trying many variations.
  25. Thanks alot that seemed to have worked, Saved me alot of time. I have been reading the MSDN notes and php on the COM class, but it does not give me info in regards to Run and returning output I tried to reuse what was working in my previuos code 2>&1 Would return results in a variable. or 1>output.log 2>error.log would return results in those log files. This no longer works, do you know a replacement? Thanks
×
×
  • 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.