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
Good Sphere
Jun 16, 2018

My work is having me start in on something on the web that is real time, amongst many users. This could be a chat or a game. I'm only starting to become familiar with this kind of development, so I first looked into Ratchet since I know a bit about PHP. I foolishly installed it onto our shared hosting. I learned a lot; including installing and messing with stuff in bash. But it doesn't allow websockets or listening ports.

Is Ratchet still in use? Any information on popular services that use it? Should I be using Symfony instead? What should I be using?

What should I be using as a VPS just to get started?

Adbot
ADBOT LOVES YOU

Good Sphere
Jun 16, 2018

Thanks for the suggestions. They got Kamatera Ubuntu server with nginx. I logged into Kamatera's dashboard for the account, and ssh'd in Mac OS's Terminal. I don't know where to even start. I'm so used to using an ftp client and the like, and I don't even know how with this yet, or if I should. A new frontier for me.

Good Sphere
Jun 16, 2018

Pile Of Garbage posted:

If you can SSH you can usually SFTP. Just connect with your FTP client of choice on port 22.

Oh duh :doh:

I wasn't using the right username. Thank you!

Good Sphere
Jun 16, 2018

I made a compressed string with Pako (zlib) in JS. I'm trying to decode it in PHP, but I get nothing if I echo it back.

The string that was encoded in js is:
code:
eJyNkDkOQCEIRO_iVaw8h9RaTcLxVXBD85dpCI8Jm0sPgknQUvAGwUQaILJMtFitDyaavpBzZTGCNobGvDcs3D7tZ33Kvn3HXFnpdS6f_cwdqn4vc3_Z_Esa8YdcAXCwqZ8
Since Pako is zlib, I thought I would need to use zlib_decode in PHP, but I get no inflated value, or at least I don't know how to see it as a normal string which I need.

code:
$inflated = zlib_decode($stringToInflate);
echo "stringToInflate = ".$stringToInflate."<br>"; // string value mentioned above
echo "inflated = ".$inflated."<br>"; // nothing

Good Sphere
Jun 16, 2018

Biowarfare posted:

It was not until I was seen remember the other JS page.

You're string "nnnnnnnnnnnnnnnnnnnnnnnnunnnnnnnnnnnnuuunnnuxunnnn..."

You must base64 decode it with the corrected URLness.

php:
<?php
$f 'eJyNkDkOQCEIRO_iVaw8h9RaTcLxVXBD85dpCI8Jm0sPgknQUvAGwUQaILJMtFitDyaavpBzZTGCNobGvDcs3D7tZ33Kvn3HXFnpdS6f_cwdqn4vc3_Z_Esa8YdcAXCwqZ8';
$f str_replace(['_''-'], ['/''+'], $f);
$f base64_decode($f);
echo zlib_decode($f);

You used JSON.stringify presumably too, so if you want to remove the double quotes from the string that you encoded in, $output = json_decode(zlib_decode(base64_decode(str_replace(['_', '-'], ['/','+'], $f))));

Thank you! That did the trick.

Good Sphere
Jun 16, 2018

Does anyone know why my image won't display using the img tag from my site? The image is generated by a php script.
Below is the image tag:


Since the tag and image code can't be seen unless quoted, it is:
code:
[img]http://majoroutput.com/eJyNkDkOQCEIRO_iVaw8h9RaTcLxVXBD85dpCI8Jm0sPgknQUvAGwUQaILJMtFi/tDyaavpBzZTGCNobGvDcs3D7tZ33Kvn3HXFnpdS6f_cwdqn4vc3_Z_Esa8YdcAX/CwqZ8=@16.png[/img]
url of image:
http://majoroutput.com/eJyNkDkOQCEI...X/CwqZ8=@16.png

My server is setup with htaccess to run a php script to create an image out of the URL with imagepng and making the header Content-Type: image/png. Works fine from my site or another domain of mine. Both domains are the same hosting, but should that even matter?

Are there any htaccess or php settings I should tweak?

Good Sphere fucked around with this message at 03:01 on Mar 4, 2021

Good Sphere
Jun 16, 2018

Weird it works from my phone, but not my desktop.

So I need https? But it works fine.. on my phone but not on my desktop. That will fix it?

e: I think I get it. The SA app may be using http instead of https somehow.

Good Sphere fucked around with this message at 03:16 on Mar 4, 2021

Good Sphere
Jun 16, 2018

Biowarfare posted:

you may also be not escaping the / in base64 correctly?

It works with https like you said. Site was approved for an SSL certificate in literally 2 minutes lol. Thanks again for all your extremely helpful input.

Good Sphere
Jun 16, 2018

Biowarfare posted:

yes congrats! the tl;dr is that by default all modern browsers will not let you include http content on a https page, because a single http-element downgrades the entire page to insecure/potentially compromised

Yup, totally makes sense. It’s been a while since I had to deal with that, so I didn’t think of that being the problem.

Good Sphere
Jun 16, 2018

I'm trying to get php installed on macOS, using Intel processor. I've had it before, but I understand there has been some changes, and the brew install is your best bet. Seems to be installed, although php is showing the script instead of the rendered page in my browser. I'm using localhost in the address bar.

I followed these instructions: https://github.com/shivammathur/homebrew-php

Good Sphere
Jun 16, 2018

ModeSix posted:

Your best and easiest bet might be XAMPP: https://www.apachefriends.org/download.html

Thanks! I was just looking into MAMPP, but now I have XAMPP installed and running, with my files.

One thing that got me was the php short tags. I turned it on, but regardless it just won't work. I know it's not safe because of the bad interactions it can have with xml. No big deal, I can write "<?php".

Good Sphere fucked around with this message at 01:34 on Jan 16, 2022

Good Sphere
Jun 16, 2018

An older workplace contacted me that made me aware of a download abuse issue with php Content-Disposition: attachment and readfile. It seems that my problem is with readfile, because although this script works, whether or not the client closes their browser, readfile reads the entire contents of the mp4, setting up the possibility of abuse with scripts initiating the download and immediately closing the progress. Something, somewhere, is running a script which clicks this link hundreds of times per second, running my php script and immediately cancelling their download, but my server is preparing that entire file to be offloaded each time.

Here's the script I'm running, when the user/abuser clicks a download link:

code:
<?php
// get MP4 address
$MP4Address = $_GET["MP4Address"];

// We'll be outputting a MOV
header( 'Content-Type: application/octet-stream' );

$filename = basename($MP4Address);

// Name file
header('Content-Disposition: attachment; filename="'.$filename.'"');

// Source file
readfile($MP4Address);
?>
I suspect that readfile is the culprit here, but without it, the client will receive an empty file. There must be a more modern, proper way of doing this, but I'm not sure what it could be.

Good Sphere
Jun 16, 2018

Thanks a lot for the suggestions. I worked on this over a decade ago, and there were some other sketchy things going on. Like, the user could send whatever address they wanted, even the server configuration if they knew what it was. This is what I have now. How does it look?

code:
<?php

$MP4Address = $_GET["MP4Address"];

// we'll be outputting a MOV
header( 'Content-Type: application/octet-stream' );


$filename = basename($MP4Address);

// name file

header('Content-Disposition: attachment; filename="'.$filename.'"');

// attach full path and download in chunks

$fullPath = "http://downloads.mydomain.com/folder/subfolder/".$filename;

function read_file($filename, $chunksize=4096) {
  if( ! $fh = fopen($filename, 'rb') ) {
    throw new \Exception('Failed to open file');
  }
  while($chunk = fread($fh, $chunksize)) {
    echo $chunk;
  }
  fclose($fh);
}

read_file($fullPath)

Good Sphere
Jun 16, 2018

nielsm posted:

Not better at all.

You need to be checking the connection_aborted() function whether the client has disconnected and then stop sending, otherwise you are definitely wasting server resources sending something to nowhere.

Sending content type application/octet-stream is a good way to ensure that browsers will almost certainly not use the video in a <video> element. Send the right MIME type for the data unless you explicitly want it to only be a file download.

If the goal is to let browsers play the video you really should also implement range requests as I suggested above. That can allow seeking in the video without downloading the full thing.

I would also suggest using a safer identifier for the data to send than just a filename. Have a database or something to look up that the requested resource is on the approved list, and optionally do other permission checks for the specific client/user. Otherwise you're far better off just serving the files directly via your web server instead of wrapping the download in a script.

Edit:
... I just noticed. You're taking the video file from a web URL and re-sending it? Is that on the same server, or on somewhere else?
Just to be sure, you do realize that what you're doing there is tell PHP to open a HTTP connection as a client to the URL you construct there, download the data at that URL, and then re-send the just downloaded data to the client that script is serving, right?

Thanks... This is a former boss contacting me asking me if I can fix it. Guess not! I have not done this stuff in a really long time.

My impression was that unless I have ignore_user_abort(true), PHP should see that connection was aborted and discontinue executing this download; at least modern versions of PHP, which I know this was updated to 7.4.29. And I thought readfile() was the exception to that.

Those seem like all good suggestions, but kind of out of the scope for a quick fix from me, unless they want to pay $$$. It's really good to know though, so thank you.

That last bit you mentioned in your edit just makes me want to serve these videos on the same hosting. I have no idea why they have a separate download subdomain with other hosting. This should have plenty of space to host it.

Good Sphere
Jun 16, 2018

Does anyone know the reasoning behind losing an install of XAMPP VM, along with all the files you put in htdocs? :(

edit: I reinstalled XAMPP VM, and the files are back! I wonder how they were stored in the first place. A search did not find it initially.

Good Sphere fucked around with this message at 16:27 on Jun 4, 2022

Good Sphere
Jun 16, 2018

Running macOS 12.1, with Xammp running, so that I can run php locally. Can I open a file with its default application with shell_exec?

edit:
This works in Terminal:
open -a "myAppName" file.txt

This does nothing in php:

code:
<?php
shell_exec("open -a "myAppName" file.txt");
?>

Good Sphere fucked around with this message at 20:45 on Jul 7, 2022

Adbot
ADBOT LOVES YOU

Good Sphere
Jun 16, 2018

musclecoder posted:

The shell_exec() method returns the output of the command, so you could see what is being output:

php:
<?php

echo(shell_exec("open -a 'myAppName' file.txt"));

My other guess is that the shell that PHP is instantiating doesn't have a full $PATH and myAppName can't be found. You may have to provide the absolute value to it. Out of curiosity, why are you trying to open a windowed application from a command line PHP script?

Also, if you're not escaping the double quotes or using single quotes like in my example you might have a plain parsing error.

Thanks for the info. I tried your suggestions. Used echo(shell_exec("open -a 'myAppName' file.txt"));, also with full path, and even without specifying the app name. Maybe it's how things are configured on the php end.

Since you're curious, here's a some background to why I want to do this. I have javascript that calls a certain numbered function that renders graphics frame by frame. Those images get saved with an ajax call to php. I string the images into a video using ffmpeg via command. First, it would be nice to be able to start making that video right away when the images are all rendered with that ffmpeg command. That's not too much of a problem though. The real reason is that I want an interface where I can make new files; one for each image generation function. These functions are kind of containers for little programs that make these animation frames. So if I want to edit one, I could just click in a list and hit open.

There's more to it than that too. They are just function names with arbitrary numbers. I could keep it that way, but in a sql database, I could have different things like titles for the functions (which I could change later without having the program affected), and descriptions.

Good Sphere fucked around with this message at 01:56 on Jul 8, 2022

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