Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS

My heart goes out to you

http://store.pulsestorm.net/products/commerce-bug-2 will help as well

Adbot
ADBOT LOVES YOU

revmoo
May 25, 2006

#basta
Anyone have a preferred deployment method at the low-level for actually pushing your files live? In the past I've swapped symlinks on the webroot with staging directories and also just automated mv to simply copy the files. Is there a better way? I'm deploying around 200mb or so each time to an app that's busy but not insane. I'd like to avoid downtime as much as possible. My testing on swapping symlinks seemed to indicate something like 20ms of downtime using that method.

Bear in mind I'm not talking about your preferred CD/CI platform, but rather what you put in your delivery scripts for the last mile (swap new content in so Apache can serve it).

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
Capistrano is probably what you want.

revmoo
May 25, 2006

#basta
Capistrano is a deployment platform. I already have one. I was asking about how I should structure my scripts to actually place the files in the web root. Again, I've already got automated deployments working and I've done it multiple ways in the past. I was just wondering if there was a better technique for pushing the files into the web root.


vvv Interesting. So I guess the symlink technique is probably as good as it gets.

spiritual bypass
Feb 19, 2008

Grimey Drawer
According to the Capistrano sample output, its default behavior is also to symlink

http://capistranorb.com/documentation/overview/what-is-capistrano/

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

revmoo posted:

Capistrano is a deployment platform? I already have one. I was asking about how I should structure my scripts to actually place the files in the web root.

Yes, Capistrano is for deploying to your server(s). Essentially, it shell's into your servers, clones your repository in a timestampped directory, does any building you need to do (build your configuration file, compile assets, run database migrations, etc), and then updates the symlink so "current" (which is what Apache points to) points to the latest release. All done atomically so if any part of your build process fails the entire release fails and you have no downtime, and can run on multiple servers asynchronously.

Aniki
Mar 21, 2001

Wouldn't fit...
EDIT: FIXED!!! I'll post my solution tomorrow, but I actually it had to do with how I incorrectly converted the query results in my AJAX function to JSON. Oi.

I am working on adding a jQuery UI autocomplete to a Laravel 4 form. I could get simple AJAX requests working via GET and while that would pass the token, it would bypass the CSRF protection. When I switched to sending an autocomplete request, I would get the following error in the console:

quote:

Uncaught SyntaxError: Unexpected token :

At that point, I tried switching to sending the autocomplete request via POST where it would have access to CSRF validation and it then yielded the following error:

quote:

POST http://localhost/Laravel_Auth/fresh/public/orders/step1Ajax 500 (Internal Server Error)

My assumption is that the problem has something to do with the Laravel CSFR token that I am using, but I am not sure how to address that issue? I saw this post another forum and ayyobro's response which talked about passing the token through the header instead of AJAX, which I did try, but I still continued to get 500 (Internal Server Error) errors, so I am not sure what to try next. The code below is just my normal attempt and does not include the changes I made to try and get passing the token through the header.

Here is my simplified route code.

php:
<?
// Authenticated group
Route::group(array('before' => 'auth'), function() {
    // CSRF protection group
    Route::group(array('before' => 'csrf'), function() {
        // Order Step 1 (POST AJAX)
        Route::post('/orders/step1Ajax', array(
            'as' => 'orders-step1-ajax',
            'uses' => 'OrderController@postOrderStep1Ajax'
        ));
    });
});    
?>
And my simplified controller code:

php:
<?
class OrderController extends BaseController {
    public function postOrderStep1Ajax() {
        if (Request::ajax()) {
            $searchSourceCode     = Input::get('searchSourceCode');
            
            $jsonSourceCodes    = DB::table('sourceCodes')
                ->distinct()
                ->take(12)
                ->where('sourceCode','LIKE', $searchSourceCode . '%')
                ->orderBy('sourceCode','DESC')
                ->get();
            
            return $jsonSourceCodes->toJson();
        }
    }
}
?>
Here is the autocomplete JS that I am using:

JavaScript code:
$(document).ready(function() {
	$( '#searchSourceCode' ).autocomplete({
		source: 	function( request, response ) {
			$.ajax({
				type: 		'POST',
				url: 		'http://localhost/Laravel_Auth/fresh/public/orders/step1Ajax',
				data: 		$( '#frmSourceCodeEntry' ).serialize(),
				dataType: 	'JSON',
				success: 	function( data ) {
					response( $.map( data.sourceCodeData, function( item ) {
						return {
							label: item.sourceCode + "(" + item.sourceCodeId + ")",
							sourceCode: item.sourceCode,
							sourceCodeId: item.sourceCodeId
						}
					}));
				}
			});		
		},
		minLength: 	2,
		select: 	function( event, ui ) {
			var sourceCodeId	= ui.item.sourceCodeId;

			if (sourceCodeId === "undefined") {
				console.log('Undefined sourceCode');
			} else {
				$( '#hiddenSourceCodeId' ).attr( 'value', sourceCodeId );
			}

			console.log(ui.item.sourceCode + ' ' + ui.item.sourceCodeId);
		}
	});
})
And here is my Blade code (includes.jQuery just includes links to hosted jQuery and jQuery UI files and includes.autosuggest includes the CSS file to style the autocomplete):

HTML code:
@extends('layout.main')
@include('includes.jQuery')
@include('includes.autosuggest')
{{ HTML::script("http://localhost/Laravel_Auth/fresh/app/js/orderStep1Autosuggest.js") }}

@section('content')
	<form action="{{ URL::route('orders-step1-post') }}" id="frmSourceCodeEntry" name="frmSourceCodeEntry" method="post">
		<div class="field">
			Source Code: <input type="search" id="searchSourceCode" name="searchSourceCode" {{ (Input::old('searchSourceCode')) ? ' value="' . e(Input::old('searchSourceCode')) . '"' : '' }}>
			@if($errors->has('searchSourceCode'))
				<span style="background:red">{{ $errors->first('searchSourceCode') }}</span>
			@endif
		</div>
		<input type="hidden" name="hiddenSourceCodeId" id="hiddenSourceCodeId">
		<input type="submit" value="Next">
		{{ Form::token() }}
	</form>
@stop
Thank you in advance and I can provide more code or follow up information if needed, I just tried to keep things down to the relevant code for this issue.

Aniki fucked around with this message at 01:02 on Oct 16, 2014

Aniki
Mar 21, 2001

Wouldn't fit...
Here is my updated code, which works for me. I'm a bit unsure why it is working now. I had initially thought that it had to do with where I was using toJson(), but upon further testing that works regardless of whether I apply it to the query after get() or to the object itself.

The route code remained the same, so I won't repost that. The jQuery code changed slightly. I did change the URL to just 'step1Ajax' instead of the full path, but both worked:

JavaScript code:
$(document).ready(function() {
	$( '#searchSourceCode' ).autocomplete({
		source: 	function( request, response ) {
			$.ajax({
				type: 		'POST',
				url: 		'step1Ajax',
				data: 		$( '#frmSourceCodeEntry' ).serialize(),
				dataType: 	'JSON',
				success:	function ( data ) {
					console.log( data );
					response( $.map( data, function( item ) {						
						return {
							label:			item.sourceCode,
							value:			item.sourceCode,
							sourceCodeId: 	item.sourceCodeId,
							sourceCode: 	item.sourceCode
						}			
					}));
				}
			});		
		},
		minLength: 	2,
		select: 	function( event, ui ) {
			var sourceCodeId	= ui.item.sourceCodeId;

			if (sourceCodeId === "undefined") {
				console.log('Undefined sourceCode');
			} else {
				$( '#hiddenSourceCodeId' ).attr( 'value', sourceCodeId );
			}

			console.log(ui.item.sourceCode + ' ' + ui.item.sourceCodeId);
		}
	});
});
And here is my updated controller code. The query was changed slightly to reference the SourceCode model of using DB::table('sourceCodes'). I also found that toJson() worked on both the query after get() and on the object:

php:
<?
class OrderController extends BaseController {
    public function postOrderStep1Ajax() {
        // Checks for an ajax request
        if (Request::ajax()) {
            $searchSourceCode     = Input::get('searchSourceCode');

            $jsonSourceCodes    = SourceCode::distinct()
                ->take(12)
                ->where('sourceCode','LIKE', $searchSourceCode . '%')
                ->orderBy('sourceCode','DESC')
                ->get();            

            return $jsonSourceCodes->toJson();
        }
    }
}
?>
The important thing is that it is working now.

Peanut and the Gang
Aug 24, 2009

by exmarx

musclecoder posted:

Yes, Capistrano is for deploying to your server(s). Essentially, it shell's into your servers, clones your repository in a timestampped directory, does any building you need to do (build your configuration file, compile assets, run database migrations, etc), and then updates the symlink so "current" (which is what Apache points to) points to the latest release. All done atomically so if any part of your build process fails the entire release fails and you have no downtime, and can run on multiple servers asynchronously.

What do you do to make sure opcache works? For me it doesn't refresh the files after the symlink change because it's still watching the old symlinked files, even though the symlink was updated.

revmoo
May 25, 2006

#basta
You'd probably have to fire off some sort of a refresh or something at that point...

opcache_reset() maybe?

revmoo fucked around with this message at 21:24 on Oct 16, 2014

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Peanut and the Gang posted:

What do you do to make sure opcache works? For me it doesn't refresh the files after the symlink change because it's still watching the old symlinked files, even though the symlink was updated.

Have Capistrano restart php-fpm. Or have php-fpm restart itself after a very low number of requests (I use 200) and the cache will be cleared automatically.

Peanut and the Gang
Aug 24, 2009

by exmarx

musclecoder posted:

Have Capistrano restart php-fpm. Or have php-fpm restart itself after a very low number of requests (I use 200) and the cache will be cleared automatically.

Is that pm.max-requests or some other setting?

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Peanut and the Gang posted:

Is that pm.max-requests or some other setting?

Yup.

code:
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 200
If you have a very highly trafficked site, that will happen very quickly. If you have a low trafficked site, bouncing php-fpm is fine. Or doing what revmoo suggested and call http://us2.php.net/manual/en/function.opcache-reset.php. If you have a multi-server environment, you'd have to do that on each server too.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
My php is not so much rusty as non existent apart from reading through code and hacking it apart. That said I am following a tutorial to make a database link for my ios app. I have the database made and populated with some data but not it needs a php service to take the mysql results and make encode them to JSON. The code the tutorial lists, with my changes, is this:

code:
<?php
 
// Create connection
$link = mysqli_connect('');
 
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
 
// This SQL statement selects ALL from the table 'data'
$sql = "SELECT * FROM data ORDER BY `UniqueID` ASC";
 
// Check if there are results
if ($result = mysqli_query($link, $sql))
{
    // If so, then create a results array and a temporary one
    // to hold the data
    $resultArray = array();
    $tempArray = array();
 
    // Loop through each row in the result set
    while($row = $result->fetch_object())
    {
        // Add each row into our results array
        $tempArray = $row;
        array_push($resultArray, $tempArray);
    }
 
    // Finally, encode the array to JSON and output the results
    echo json_encode($resultArray);
}
 
// Close connections
mysqli_close($result);
mysqli_close($link);
?>


The issue is that I get nothing when I run this when uploaded to the server. What did I mess up?

thegasman2000 fucked around with this message at 00:25 on Oct 21, 2014

o.m. 94
Nov 23, 2009

There could be multiple points of failure in this code. Have you got some kind of error output? If it's not erroring, then try examining the contents of $resultArray and work backwards, as this is procedural and at some point it'll be cocking up.

Also $tempArray looks redundant, you can just use $row in its place.

o.m. 94 fucked around with this message at 22:21 on Oct 20, 2014

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

o.m. 94 posted:

There could be multiple points of failure in this code. Have you got some kind of error output? If it's not erroring, then try examining the contents of $resultArray and work backwards, as this is procedural and at some point it'll be cocking up.

Also $tempArray looks redundant, you can just use $row in its place.

This is the link to the file...

Nothing outputted at all... I have no idea what half that code is doing to be quite frank. :/

thegasman2000 fucked around with this message at 00:25 on Oct 21, 2014

o.m. 94
Nov 23, 2009

When I request a PHP file, the server executes it and only displays the results of the code (if there is even any output), so I won't be able to read it without accessing the file directly, and anyway you've posted the code above.

What you need to do here is get error logging working, and have it dump the error to the screen so you can see where your script is failing.

If it's not failing, then start by examining your $resultArray variable with var_dump(), and work backwards through each step to see where you're not getting any results. Perhaps your query is wrong, etc.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

o.m. 94 posted:

When I request a PHP file, the server executes it and only displays the results of the code (if there is even any output), so I won't be able to read it without accessing the file directly, and anyway you've posted the code above.

What you need to do here is get error logging working, and have it dump the error to the screen so you can see where your script is failing.

If it's not failing, then start by examining your $resultArray variable with var_dump(), and work backwards through each step to see where you're not getting any results. Perhaps your query is wrong, etc.

with my babies first php knowledge... Is it best to add an echo after each point to see if it gets that far?

o.m. 94
Nov 23, 2009

Sure, you would want to check that your mysqli_query() call returned a truthy value, because it could not and thus the block where you're expecting output would never be executed.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

o.m. 94 posted:

Sure, you would want to check that your mysqli_query() call returned a truthy value, because it could not and thus the block where you're expecting output would never be executed.

http://imgur.com/RHr2jTe

This means my query works right? I copied it from here.

Mogomra
Nov 5, 2005

simply having a wonderful time

thegasman2000 posted:

This is the link to the file... http://moneyspiderdesign.com/service.php

Nothing outputted at all... I have no idea what half that code is doing to be quite frank. :/

The fact that there's no output at all, and that the link's status code is 500 makes me think that there is some sort of fatal error, and error reporting is turned off. If you can check the error log on that server, or turn on error reporting for a second to see what's happening, you're in luck.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

Mogomra posted:

The fact that there's no output at all, and that the link's status code is 500 makes me think that there is some sort of fatal error, and error reporting is turned off. If you can check the error log on that server, or turn on error reporting for a second to see what's happening, you're in luck.

I turned it on, I think...

I uploaded a non hacked up version called OrginalService.php and it gives this error.


Warning: mysqli_close() [function.mysqli-close]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /home/dlfvyzmg/public_html/OriginalService.php on line 36

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/dlfvyzmg/public_html/OriginalService.php on line 36


for this code
code:

<?php
 
// Create connection
$con=mysqli_connect('');
 
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
 
// This SQL statement selects ALL from the table 'data'
$sql = "SELECT * FROM `data` ORDER BY `UniqueID` ASC";
 
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
    // If so, then create a results array and a temporary one
    // to hold the data
    $resultArray = array();
    $tempArray = array();
 
    // Loop through each row in the result set
    while($row = $result->fetch_object())
    {
        // Add each row into our results array
        $tempArray = $row;
        array_push($resultArray, $tempArray);
    }
 
    // Finally, encode the array to JSON and output the results
    echo json_encode($resultArray);
}
 
// Close connections
mysqli_close($result);
mysqli_close($con);
?>

thegasman2000 fucked around with this message at 00:24 on Oct 21, 2014

o.m. 94
Nov 23, 2009

You're trying to close the connection twice by passing in the results variable first time. You should only need to do mysqli_close($con) which is the actual connection.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

o.m. 94 posted:

You're trying to close the connection twice by passing in the results variable first time. You should only need to do mysqli_close($con) which is the connection.

Yeah I wondered that, so i commented out the first mysqli_close($result) and now it gives nothing again. No errors or anything. :suicide:

o.m. 94
Nov 23, 2009

Okay, so you know that it isn't erroring anymore. We can therefore logically conclude that your script is not outputting anything. But we also know that you have an echo statement in the code. This leads us to two possibilities:

1. The echo line is never reached. Why might that be? Is there a condition that needs to be met before that echo line is reached?
2. The echo line is reached, but you can't see anything because it's outputting a falsy value which PHP echo will not display anything for

Hint: Instead of echo, use var_dump().

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
ok so I added a breakpoint and commented out the line
if ($result = mysqli_query($con, $sql))

It now gets past that but errors with
Fatal error: Call to a member function fetch_object() on a non-object in /home/dlfvyzmg/public_html/OriginalService.php on line 25

o.m. 94
Nov 23, 2009

If you remove the expression $result = mysqli_query(...), then you have no $result variable. If you have no $result variable, you can't call the method $result->fetch_object() on it later on in your code.

We could go on like this for hours. I would reccomend you read up on PHP some more and learn to do basic debugging. Don't remove lines of code, just inspect your variables and see if they contain what you expect.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

o.m. 94 posted:

If you remove the expression $result = mysqli_query(...), then you have no $result variable. If you have no $result variable, you can't call the method $result->fetch_object() on it later on in your code.

We could go on like this for hours. I would reccomend you read up on PHP some more and learn to do basic debugging. Don't remove lines of code, just inspect your variables and see if they contain what you expect.

Your right, I don't really want to go wading through php code though. I really only want this bloody service so I can do what I am currently learning which is Swift for IOS. The tutorial code is clearly poo poo which isnt helping, perhaps I need a new tutorial! Thanks for your help though.

o.m. 94
Nov 23, 2009

The tutorial isn't the problem (although yes that code is poo poo); it's that you aren't capable of debugging the code. Like I said, start with your point of output, and inspect it:

var_dump(json_encode($resultArray));

Look at the documentation for json_encode: http://php.net/manual/en/function.json-encode.php

If you get FALSE, then your argument, $resultArray has a problem. Step back through your code:

var_dump($resultArray);

It may be that your $resultArray is empty. Find out why. Keep stepping back through the code, examining the contents of each variable 'til you find the problem.

kiwid
Sep 30, 2013

So, I've been tasked with putting a video on our website. Easy enough just using HTML5.

Here are the problems:
1. The video changes two to three times a day (kind of like a podcast but relating to our industry) and I don't want to be doing this manually.
2. I get the videos via FTP access which has access to all the videos in the root ftp folder, all named with no standard.
3. It does appear that I could use the date modified timestamp to show the latest video.

What is the best way to go about this?

kiwid fucked around with this message at 18:11 on Oct 21, 2014

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Well, there's ext/ftp, which you probably have installed already. You can use that to poke around and pull files down, but it'll be clunky.

revmoo
May 25, 2006

#basta
- Crontab shell script runs hourly and connects to FTP to check for new video based off timestamp. Store timestamp in a plain text file that the shell script can consult
- If it finds a video, copy it to webroot

If you just need the latest video then keep the file name the same and overwrite it and you're done. If you need to be able to show previous videos then you'll probably need to write a CLI php script that is triggered from the shell script that goes and does whatever database updates you need. This is all assuming your video codec is automatically HTML5-friendly and ready to post.

You'll need to do some homework to find a way to automate FTP via a shell script but it shouldn't be too hard to figure out.

kiwid
Sep 30, 2013

revmoo posted:

- Crontab shell script runs hourly and connects to FTP to check for new video based off timestamp. Store timestamp in a plain text file that the shell script can consult
- If it finds a video, copy it to webroot

If you just need the latest video then keep the file name the same and overwrite it and you're done. If you need to be able to show previous videos then you'll probably need to write a CLI php script that is triggered from the shell script that goes and does whatever database updates you need. This is all assuming your video codec is automatically HTML5-friendly and ready to post.

You'll need to do some homework to find a way to automate FTP via a shell script but it shouldn't be too hard to figure out.

Yeah I can definitely figure out the specifics. I just wanted to know the general flow of how you'd do it and this post just confirms essentially the way I was thinking of doing it in the first place. Luckily the video is HTML5-friendly so this should be as straight forward as you detailed.

McGlockenshire posted:

Well, there's ext/ftp, which you probably have installed already. You can use that to poke around and pull files down, but it'll be clunky.

Is PHP's built in FTP functionality the way to go or is there something like Guzzle but for FTP out there that is better?

kiwid fucked around with this message at 19:45 on Oct 21, 2014

kiwid
Sep 30, 2013

gently caress, so I tried to implement this tonight...

php:
<?
// connect to the ftp server
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
ftp_pasv($conn, true);

// get all mp4 files into an array with date modified timestamp
$data = [];
$files = ftp_nlist($conn, '');
foreach ($files as $file) {
    if (pathinfo($file, PATHINFO_EXTENSION) == 'mp4')
    {
        $data[$file] = ftp_mdtm($conn, $file);
    }
}

arsort($data, SORT_NUMERIC); // sort the array by date modified, newest first
$video_time = Settings::get('video_time'); // get the date modified of the last file downloaded

// foreach mp4 file, if file is newer or doesn't exist, download it
foreach ($data as $file => $time)
{
    if (($time > $video_time->value) || ( ! file_exists('video/video_comments.mp4')))
    {
        ftp_get($conn, 'video/video_comments.mp4', $file, FTP_BINARY);
        Settings::update('video_time', $time);
    }

    break; // only check the newest file
}

ftp_close($conn);
?>
I'm running into 504 gateway timeout issues (30seconds). Would that be because there is like 1000 video files among thousands of other types of files, like .jpg, .gif, etc. in the FTP directory?

edit: to be exact, there are 5997 files in this ftp directory + 10ish every day.

kiwid fucked around with this message at 02:52 on Oct 22, 2014

McGlockenshire
Dec 16, 2005

GOLLOCKS!

kiwid posted:

I'm running into 504 gateway timeout issues (30seconds). Would that be because there is like 1000 video files among thousands of other types of files, like .jpg, .gif, etc. in the FTP directory?

edit: to be exact, there are 5997 files in this ftp directory + 10ish every day.

So, plan A: modification time won't be changing on these files, right? If so, it'll probably be safe to cache the result of the ftp_mdtm calls, which are probably what's sucking up all the run time.

Plan B: Run it by cron, no worries about hitting a gateway timeout that way, and you can just disable the execution time limit if need be.

Plan C: Hire a team of assassins to take out the idiots upstream responsible for the video delivery method and have it replaced with something sane that involves active notifications of new or changed content instead of having to index a few thousand things every time.

Experto Crede
Aug 19, 2008

Keep on Truckin'
At work, I run a unix command using watch to view the queue on our PBX, ideally I'd like to find a way to show this in a browser also in real time.

Is there a way in PHP to basically to view the live output of a command through shell_exec?

kiwid
Sep 30, 2013

McGlockenshire posted:

So, plan A: modification time won't be changing on these files, right? If so, it'll probably be safe to cache the result of the ftp_mdtm calls, which are probably what's sucking up all the run time.

Plan B: Run it by cron, no worries about hitting a gateway timeout that way, and you can just disable the execution time limit if need be.

Plan C: Hire a team of assassins to take out the idiots upstream responsible for the video delivery method and have it replaced with something sane that involves active notifications of new or changed content instead of having to index a few thousand things every time.

Definitely would like to go with Plan C. However, I'll give Plan A a try. Another option I was thinking was to use the ftp_rawlist command and parse the date/time from that. It's a bit messier but I can get a rawlist in 7 seconds, rather than timing out.

spacebard
Jan 1, 2007

Football~

Experto Crede posted:

At work, I run a unix command using watch to view the queue on our PBX, ideally I'd like to find a way to show this in a browser also in real time.

Is there a way in PHP to basically to view the live output of a command through shell_exec?

Allowing shell execution is not really best practice, but it's possible. Writing the output to a file accessible to the web server would be better. Then have a HTML page that picks up the file with some javascript and updates it. Could be a quick little React/Ember/Angular thing (the latter two if you wanted to over engineer it).

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

Experto Crede posted:

At work, I run a unix command using watch to view the queue on our PBX, ideally I'd like to find a way to show this in a browser also in real time.

Is there a way in PHP to basically to view the live output of a command through shell_exec?

You can use popen() instead of shell_exec(), which will give you a stream you can read from just like a file.

Adbot
ADBOT LOVES YOU

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror
Does anyone know a way to get the SSH2 functions to connect via a proxy? Or any SSH library that will let me connect via a proxy? The only other thing I can think of doing is using proc_open('proxychains ssh...') but I really don't want to wrangle the input/output pipes if I can help it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply