Hi, Artisan
In this article i will share with you how to run or execute python 3 script in your laravel application. some people ask me why you need to run python 3 scripts in laravel? why you don't write same logic in laravel? so, i have also answer for that people.
Recently i have been work one laravel application. our laravel application also working fine and no need to any extra requirement in it. but recently we want to add some functionalilty in laravel application. we want to add image recognition in our application as you all know this functionality not built easy with laravel script.
As you all know python do any things. here is some common examples.
first, we need to write very simple python script for testing.
# User inputs the string and it gets stored in variable str
str = input("Enter a string: ")
# counter variable to count the character in a string
counter = 0
for s in str:
counter = counter+1
print("Length of the input string is:", counter)
laravel already provie a Process class for run the script in laravel. so, we also use this class and will run our python script in the laravel application.
public function testPythonScript()
{
$process = new Process("python3 /var/www/laravel/myLaravelApp/app/PythonScript/test.py");
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$data = $process->getOutput();
dd($data);
}
i hope you like this article. in next article i will share with you how to export 100M record with help of python and laravel.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel8 - Validation Required if Another Field is Empty
In this article, I will share with you h...How to remove white space from the beginning of a string in PHP
Use the PHP ltrim() function...How to create custom select box in HTML using CSS and jQuery
Use the CSS :selected Pseudo-class with...Show read more link if the text exceeds a certain length using jQuery
Use the JavaScript substring() ...Python MySQL Database Connection using MySQL Connector module
Python is fast when working and analysin...