Write PHP code in Python [duplicate] - php

This question already has answers here:
Execute php code in Python
(5 answers)
Closed 5 years ago.
Would like to know whats the Python function to call if I would like to write PHP script in Python.
I am trying to utilise a PHP function that would take in values from a table created in python, operate on the text in PHP (using that PHP library) and throw the result back into a python table.

The question here: Execute php code in Python has some answers which may help you. Notably this one by Sjoerd:
import subprocess
result = subprocess.run(
['php', 'image.php'], # program and arguments
stdout=subprocess.PIPE, # capture stdout
check=True # raise exception if program fails
)
print(result.stdout) # result.stdout contains a byte-string
It should be reasonably easy to make that work for your use case. In this case rather than directly writing PHP in python you will write the php in another file and then call that with python and capture its results.

Related

How to display output of 'top' command on web browser using Php [duplicate]

This question already has answers here:
Get cpu percent usage in php
(6 answers)
Parsing output of "top" command (Shell) with PHP
(2 answers)
PHP equivalent to Linux's top command
(3 answers)
Closed 5 years ago.
I have a simple php script 'top.php' with shell_exec function.
Code:
<?php
echo shell_exec("top");
?>
What I am looking for is to view results of 'top' command on a web browser. So, if I access http://192.168.1.1/top.php I want to see results of top command. It is essential to view results of top command periodically as you would see in a command line terminal.
However, when I access 'http://192.168.1.1/top.php' on web browser, it does not display anything. Same behaviour when I execute top.php on command line (as 'php top.php').
I am not sure what or where it is going wrong.....
top on the command line by default just keeps running, so I suspect what's happening here is that it's not exiting and returning output to PHP. The -n 1 flag should address that:
<?php
echo shell_exec("top -n 1");
?>
This would give you one "page" of output from top to display on your webpage. In order to refresh it, you would of course just refresh the webpage.
To make something a little smoother (where you don't have to refresh the page), you could have a page which makes an AJAX request to this PHP script and then displays the output on the page. That AJAX request could then be scheduled with setInterval() in JavaScript to occur ever X seconds as you see fit.

Perl: How to do a PHP-style include? [duplicate]

This question already has answers here:
Is there any way to "auto-use" certain modules everytime I write a script?
(2 answers)
How can I export a list of modules with my own module?
(1 answer)
Closed 7 years ago.
In a PHP include, code is parsed as if it was written right into the source file. You get the same result as if you literally copy and pasted file A into file B.
I'm looking for a way to do this in Perl. The number of libraries I have to 'use' in every script is getting annoyingly large, and especially annoying is having to use v5.14 just so I can have the say function. I'm actually looking up how to alter the interpreter to always use the latest version of Perl at this moment, compatibility with the rest of the world be damned, but this won't solve the rest of my list of includes.
Edit: none of the linked answers answer the question.
The equivalent of PHP's include is do EXPR. There is also require EXPR, which is like require_once, and use, which will also call import on the package.
However that is probably not what you want. If you have a lot of .pl scripts without packages, you are dealing with legacy code. You need to be carefull what you require and include where.

curl php bash sign [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I have a code and need help. I have a curl call with a bash sign like this
http://example.com.ua/script.php
clients send me data using a script but some send me the bash # which I need to save all the data to my database. When I get $_SERVER I don't see all the data how can get all the data?
for example:
I have
http://example.com.ua/script.php#code1234
I need to save:
example.com.ua/script.php#code1234
but I see
example.com.ua/script.php
PHP does not have access to the location hash, period.
You only have access to querystrings in PHP, and if you need to get the hash, you would have to use javascript to get it, and send it to your PHP script with ajax.

Is there any other alternative to PHP which allows me to deploy unreadable code on a server? [duplicate]

This question already has an answer here:
Closed 10 years ago.
I am developing a CMS which has a PHP Encryption engine. But as the PHP code is completely visible, the method of encryption of data is easily compromised as every person who purchases the product can read the code. I want to pre compile the PHP or use any other server side scripting language that allows me to give a file containing the byte code of the program and which carries out the exact same function as the original PHP file. Is there any such language?
I know that perl can be precompiled.
This might be useful: http://www.perlmonks.org/?node_id=402933

How can I call a python instance using php? [duplicate]

This question already has answers here:
php : Capturing the command output
(3 answers)
Closed 8 years ago.
I have a PHP program, and a Python program. You can think that the Python program is like a robot or machine. Typically, it will use a database, do some analysis and return result for you. It is a plain text console application.
I would like to let the user use the program via a web interface. So, I would like to use PHP, accept user input, and the pass it to the Python program, and back to the user.
How can I achieve it? The Python program is always running on the server, which will keep analysis data from the web and the user input, so it can't easily convert to become a script on server side.
Any ideas?
You might want to check exec function. You can pass the input from user as parameters to the python script and get back the output from it.
Take a look into http://www.csh.rit.edu/~jon/projects/pip/

Categories