r/PHPhelp • • Dec 29 '22

What should I look out for when creating a web app (specifically when handling lots of files)?

8 Upvotes

I'm creating a web app that allows users to upload and browse files. I haven't done this before and I'm nervous about handling a large number of files.

What things should I put in mind when creating this app? My two main "problems" are creating tabbed views for file items and deciding the best way to save the actual files (in database vs file system) my current method is saving the file on the hard drive and its path in a database.

Any pointers that could save me "newbie mistakes" are appreciated.

I'm creating this thing in pure PHP by the way.


r/PHPhelp • • Dec 28 '22

What's the maximum value to set in ini_set('memory_limit', -1) without having problems on the server?

8 Upvotes

Hello

I need to change the memory_limit on my code to avoid some problems related to the memory

So I did : ini_set('memory_limit', -1)

But today my server (Apache2) was down because of memory issue!

I'm wondering what's the maximum value can I put on memory_limit without having this kind of problems . I have 16GB of memory on my server


r/PHPhelp • • Dec 23 '22

Solved PHP is a good programming language to study in 2023?

8 Upvotes

Hi everyone, I started to study programming in this year, In my institute I am studying PHP and I would like you all to tell me if PHP is a good programming language to study yet? Thanks.


r/PHPhelp • • Dec 14 '22

Does max_file_uploads have a limit?

8 Upvotes

We found the max_file_uploads limit today after a customer tried to upload 30 files at a time (the default for max_file_uploads is 20). I opened a ticket and the higher ups asked what is the biggest value it could be set to ("Could the server handle a max_file_upload of 100000000?"). I have searched, but can't find anything that tells me the limit (if there is one).

Is there a limit for this? Can I set it to -1 to mean unlimited (and is that a bad idea if it is possible)? https://www.php.net/manual/en/ini.core.php#ini.max-file-uploads doesn't help much.


r/PHPhelp • • Dec 12 '22

Starting with PHP

8 Upvotes

I want to start learning php but the tutorial I was referring to uses XAMPP and I already have MySQL workbench installed on my pc and they both keep clashing together. Is there a better way of running php ?


r/PHPhelp • • Nov 28 '22

Solved Can I use PHP to add line breaks to CSS code in a parsed .css file?

8 Upvotes

I'm currently using ACF on a WordPress site to define variable typographic styles. These styles are referenced in a PHP file which then generates variable CSS rules in a parsed, temporary CSS file, which is then enqueued in my functions.php file.

The only problem is that I can't figure out how to ensure that each string returned in my CSS file is placed on a new line. Googling the issue brings up \r\n, PHP_EOL and nl2br() as proposed solutions, but these just seem to be ways to generate HTML line breaks instead of adding line breaks to the CSS file itself.

Both the PHP code I've used, the resulting CSS and what I'm actually hoping to get can be found here:

https://pastebin.com/8UfY9EMg

I'm brand new to PHP so I'm sure I'm missing something obvious, but any help would be much appreciated!


r/PHPhelp • • Nov 27 '22

Delivering a reliable SPA with subscription options. payments and security covered, in a few weeks, learning from scratch

8 Upvotes

Help needed for SPA project

I need to deliver a SPA which is able to receive payments via a payment API and allows subscription payments. And this I must achieve within a few weeks!

After some research I found it would be a good investment to learn PHP, Laravel & Livewire for this purpose and for potential similar projects.

I am not a great friend of Javascript and it's frameworks. So, little to no JS would be great.

  • Am I right in assuming that I may achieve a relatively decent looking SPA without touching much JS, with help of Laravel and Livewire?

I already have some programming skills with Python. But I have near zero affinity with PHP ecosystems.

  • What is the most no-nonsense way to learn all this from scratch?

  • Which exact way you would follow to achieve my goal? Courses, methods, any idea is appreciated.

Thank you for any guidance that may enlighten my path.


r/PHPhelp • • Nov 21 '22

Solved Extensionless scripts in PHP_CodeSniffer

8 Upvotes

Is there a way to configure phpcs.xml to analyse command-line scripts that do not have an extension?

#!/bin/env php
<?php

phpinfo();

If I use <file> to set the path of the script directory (or even individual files), it seems that the extensions argument still kicks in and my files are ignored.

<arg name="extensions" value="php,phtml"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<file>.</file>
<file>scripts</file>
<file>scripts/phpinfo</file>

r/PHPhelp • • Nov 19 '22

Solved AND OR condition not working

8 Upvotes

I am creating a registration form and trying to get the source of registration of the user, my code is given below.

The issue is the registration form only work with AND condition and not with OR condition, please have a look into my code and suggest what needs to be modified

I am not taking sql injection protection into consideration as of now hence didn't used PDO

<?php

try{
include 'connection.php';
$con = mysqli_connect($servername,$username,$password,$database);

$json = file_get_contents('php://input');
$obj = json_decode($json,true);

$uqid = md5(uniqid().mt_rand());
$fullname = $obj['fullname'];
$email = $obj['email'];
$emailformat = filter_var($email, FILTER_VALIDATE_EMAIL);
$profilePic = $obj['profilePic'];
$password = $obj['password'];
$source = $obj['source'];

if(empty($email) || !$emailformat){
echo json_encode('Email issue');
exit();
}

//Checking if user is already registered
$CheckSQL = "SELECT * FROM users WHERE email='$email'";
$check = mysqli_query($con,$CheckSQL);
$row = mysqli_fetch_array($check, MYSQLI_ASSOC);  
$count = mysqli_num_rows($check);  
if($count == 1 AND $source == "Google" OR $source == "Facebook"){
//login register
echo json_encode("User login successfully");
exit();
}
else{
    //register new user
     $Sql_Query = "INSERT INTO users (uqid, fullname, email, profilePic, password, source,registerDate) values ('$uqid', '$fullname', '$emailformat', '$profilePic', '$password', '$source', NOW())";
}
    if(mysqli_query($con,$Sql_Query)){
      echo json_encode("User registered successfully");
      exit();
    }
}

catch (\Exception $ex) {

die($ex->getMessage());

}

?>

r/PHPhelp • • Nov 17 '22

Solved PHP Abstract Classes, PHP Interfaces

8 Upvotes

I read about it online and still can't understand what these two is about. How does it work and when do you use these two? Can someone give example and explain these to me in simple words? Thanks!


r/PHPhelp • • Oct 25 '22

Greedy Algorithm with added functionality.

8 Upvotes

I have a specific function that I require assistance with. I am busy with a project where licenses need to be allocated based on a specific quantity as per user input. The licenses are bundled as an example 1 user, 5 users, 10 users 20 users and 50 users. If the input is 20 it's easy to determine that the license that needs to be allocated is one for 20 users. If the input is 27 I can use a greedy algorithm to determine the best way to allocate would be 1 x 20 users, 1 x 5 users and 2 x 1 user.

My problem now though is that in most cases there is a threshold where it is actually more cost effective to rather allocate a license that caters for more users compared to the input specified. For example 19 users it is more cost effective to provide a license for 20 compared to 1 x 10 users, 1 x 5 users and 4 x 1 user.

What would be the best approach to approach the above and avoid unnecessary recalculation and comparison. The obvious approach is to run the greedy algorithm and get a total cost and compare the cost of another license where total users > users as per input.

The issue I see is already making me scratch my head. Is for example 28 users. I already know the most cost effective approach is 1 x 20 users and 1 x 10 users. The next license up is 50 users. So it will be too expensive. However the greedy algorithm gives me 1 x 20 user, 1 x 5 user and lastly 3 x 1 user.

Any assistance will be greatly appreciated.


r/PHPhelp • • Oct 22 '22

Solved PHP server security?

8 Upvotes

Hello everyone, I pray that you are all doing well.

You might have noticed that the title is a question, that's because I'm not really sure what exactly I'm looking for.

But you might, so here is what I'm specifically asking about.

When we create a database in phpmyadmin, we later go to our coding program and start writing this :

<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "whatever the database name is"; $conn = mysqli_connect($servername, $username, $password, $dbname); Now clearly this is not secure. And someone told me once that the username and password should not be like this. But all the tutorials do this, so what's the correct thing to write? Thank you all in advance, have a good day/night 😁 The Lord be with you all and save you all your families and friends 🤍


r/PHPhelp • • Oct 12 '22

Tool to assist with PHP migration (Rector?)

8 Upvotes

I'm trying to set up a linter to prepare a codebase for a PHP upgrade, being PHP/8.1 the ultimate goal. I thought Rector was the most obvious candidate, but its LevelSetList::UP_TO_PHP_... rule sets are a bit enthusiastic. I only really need to handle deprecations and removals, but I end up with mere subjective changes like moving class property definitions to constructor promotion and adding readonly qualifiers.

I can exclude individual rules as they pop in, but I feel I'm just fighting against the tool.

Am I missing something? Is there a better tool I could be using?

Edit: I've analysed my first old project (which was already working fine in PHP/8.0) with phpcs, phpstan and php-cs-fixer. After fixing the issues reported, I've upgraded my local PHP to 8.1 and, boom!, deprecated notices all around the place. I had even forgotten lots of short open tags, which I wanted to get rid of (I was using it to comment out unwanted HTML code—it's literally a project from around 1999-2000).


r/PHPhelp • • Sep 20 '22

Solved XAMPP Mac: Apache and MySQL won't start

8 Upvotes

Installed XAMPP on Mac with manager-osx.

Both MySQL Database an Apache Web Server both only go Yellow status of Starting... and then goes back to Stopped.

The only thing that can start is ProFTPD.

Update1:

Got Apache Web Server to work only by running this command: sudo /Applications/XAMPP/xamppfiles/bin/apachectl start Weird how I can't get it to work just clicking Start in XAMPP. MySQL still won't start.

Update2: Had MySQL instance running, went to system preferences in Mac > MySQL > Stopped it.


r/PHPhelp • • Sep 17 '22

How to scan large php directory asynchronously

8 Upvotes

Hello, so it seems I have never encountered such problem and I am looking for a way or an example how it can be done.

The problem is I have large directory I want to scan it using PHP, even if max_execution_time is still long enough it potentially can break and also by running long script at once it's really not clear what is the state of the process and how far it already scanned.

Is there a technique a way or something that would help me to overcome this issue.So let's say I am scanning a large directory I want my script to return scanned files for each directory so I can keep adding it using JavaScript and building the Folder Structure dynamically. The part I don't get is how do I resume recursive function later? Let's say I scanned a directory 'a' how do can I know later what to scan next? Since as I said I can't just run long executing script and to find out all the paths, files, directories at once. Theoretically I could keep the array of paths that were already scanned, but then if I get back to scanning latter I still have to skip all those paths that were scanned and it takes time, processing power to do that obviously.

The reason I need this is when scanning directory I want to have kinda like a realtime indicator what has already been scanned and where the scanner is going and such.

Any help, advice would be really appreciated


r/PHPhelp • • Sep 13 '22

Suggestions for PHP web scraper libraries?

8 Upvotes

I am looking for suggestions on web scraping libraries, to scrape non-JavaScript pages. So just a standard scraper, not something that has to render with a browser, like Symfony Panther.

I am familiar with Goutte, and when I searched "goutte alternatives" I found links to Embed, PHP Scraper, and PHP Spider. But I haven't tried them, or know if there's any reason to prefer one over the others.

Are there are any other significant PHP scraping libraries? What is currently the most popular or most standard PHP scraper? What should I be looking for in terms of choosing between the options?


r/PHPhelp • • Sep 12 '22

Solved Code coverage with PHP 8.2

8 Upvotes

I've downloaded a PHP 8.2 nightly and testing out my code...

vendor/bin/phpunit --coverage-html coverage/html

PHPUnit 9.5.24 #StandWithUkraine
Runtime: PHP 8.2.0-dev with Xdebug 3.2.0alpha3

....

Generating code coverage report in HTML format ... done [00:03.389]

coverage/html dir is empty

thoughts?


r/PHPhelp • • Jul 29 '22

Solved What is the relation between PHP and Apache

8 Upvotes

Apache need PHP to work, or could be any other language?


r/PHPhelp • • Jul 04 '22

Vanilla PHP project structure

8 Upvotes

Hello all

I'm getting into PHP after working primarily with NodeJS for years. I'm confused as to how a website with a PHP back-end (without any framework like Laravel) works. I'm going through a book: 'Learning PHP, MySQL, JavaScript, CSS & HTML5' by Robin Nixon, which endeavours to teach a whole lot more than just PHP, but seems like a good primer on the language and its capabilities.

From what I've seen thus far, PHP files (with HTML embedded inside) can be sent directly to the browser to be parsed and displayed. So one doesn't need .html files at all. Is that a common thing in PHP projects?

Is LAMP/LEMP the standard way of doing things with Vanilla PHP projects? I use Ubuntu and have been doing all my PHP coding in the /var/www/html directory and using localhost/filename.php to see the output.


r/PHPhelp • • Jun 15 '22

New to PHP: Associative arrays

8 Upvotes

Hello people, I am a Python and JS programmer who recently decided to learn PHP. So I am here playing around with PHP and was stuck with something related to Associative arrays.

My Code:

<?php $list = \["a" => "Yooo", 1 => 2, true=> true\]; print_r($list); ?>

The output:

Array

(

[a] => Yooo

[1] => 1

)

My questions:

  1. Can I use any datatypes for keys like strings, numbers or boolean?

  2. Why am I getting that output? I have three items in my array but I only get two in the console.


r/PHPhelp • • May 27 '22

Solved php shell_exec not working with pipes

8 Upvotes

Hi all I'm trying to SvtAv1EncApp tools via web interface, I try to us both exec() shell_exec() with no success , BTW I print the command and run it into the shell directly and it's works perfectly fine.

$cmd2="/usr/local/bin/ffmpeg -loglevel -8 -i "$mp4" -s 960x540 -strict -1 -f yuv4mpegpipe - | /usr/local/bin/SvtAv1EncApp --no-progress -i stdin --rc 0 -q 38 --preset 8 -b stdout 2>/var/www/vl/ffmpeg.log | /usr/local/bin/ffmpeg -loglevel -8 -y -i - -i "$mp4" -map 0:v -map 1:a:0 -c:v copy $a '".$mpa."_.mkv' & ";

shell_exec( $cmd2 ) ;

Here is the text of echo $cmd2 output

/usr/local/bin/ffmpeg -loglevel -8 -i "FHD.mp4" -s 960x540 -strict -1 -f yuv4mpegpipe - | /usr/local/bin/SvtAv1EncApp --no-progress -i stdin --rc 0 -q 38 --preset 8 -b stdout 2>/var/www/vl/ffmpeg.log | /usr/local/bin/ffmpeg -loglevel -8 -y -i - -i "FHD.mp4" -map 0:v -map 1:a:0 -c:v copy -strict -2 -c:a libopus -b:a 64k 'FHD_.mkv' &

=Update=

I kinda solve it , I don't know why but exec() successfully executed the script , I created new bash script from command line thanks to @xisonc suggesting nano /usr/local/sbin/av1c with this value

!/bin/sh

touch /var/www/vl/ffmpeg.log /usr/local/bin/ffmpeg -loglevel -8 -i "$1" -s 960x540 -strict -1 -f yuv4mpegpipe -
| /usr/local/bin/SvtAv1EncApp --no-progress -i stdin --rc 0 -q 38 --preset 8 -b stdout 2>/var/www/vl/ffmpeg.log
| /usr/local/bin/ffmpeg -loglevel -8 -y -i - -i "$1" -map 0:v -map 1:a:0 -c:v copy -strict -2 -c:a libopus -b:a 64k "$2"

On the php script i had this

$cmd2="/usr/local/sbin/av1c '$mp4' '$mpa"."_.mkv'   2>/dev/null >/dev/null & " ; 
exec( $cmd2 , $pid, $r )    ;   
var_dump(  $r )                ;

var_dump returns 0 , and since the bash script are silent I don't need to see the output , now I want to change it to wok on the background it's running on background now after adding 2>/dev/null >/dev/null & at the end of the command .


r/PHPhelp • • May 24 '22

self-taught coder seeking help

8 Upvotes

Hey guys,

I'm creating an app that communicates with an API using the cURL library. I'm stuck trying to update my CA root certificates, I have the certificates downloaded but am not sure where and how to update it. I have looked through php.ini for 7.4.16 (my version), but there doesn't seem to be place to change the certs or even have certs set in the first place.

I found a risky work around by turning off CURLOPT_SSL_VERIFYPEER, I don't want to do that since it's a security risk.

Not sure what I'm doing wrong, have read through everything I could find online but still stuck.

Would appreciate any help! Thank you!


r/PHPhelp • • May 17 '22

Deploying PHP Application to AWS

8 Upvotes

Hello. I have a PHP app that's set up to run on PHP 7.x and I'm thinking of getting it running on AWS. I started out looking at Elastic Beanstalk on AWS but it only supports PHP 8. I started looking into upgrading the app to 8, but I am fairly green at PHP and it seems a bit of a daunting task.

I ran "composer why-not php 8" and was shown a few packages that we're ready to support the version. One of the packages seems to not have been updated since Nov of 2020 and doesn't appear that it will ever support 8 - can I coerce it somehow...?

Should I try to run it in AWS on an EC2 instance with PHP 7.x ... anyone have any recommendations?

Thanks a lot. I hope there's enough here to generate some dialog and I can focus in on the issues...


r/PHPhelp • • Dec 28 '21

Solved My try/catch and error throwing knowledge is really lacking

8 Upvotes

Hi, My try/catch and error throwing knowledge is really lacking. Is there some resource, tutorial, or video that explains everything about these related concepts in a way that really dumbs it down for those of us that are not blessed with good comprehension skills.

Thanks.