首先感谢抽时间阅读!
我尝试通过浏览器登陆本地服务器运行我的PHP文件,无法正常运行。我安装的是Appserver安装包2.6.0版本(Appserver网站),包内包含的软件版本为:Apache 2.2.8、PHP 6.0.0-dev。为了找出错误原因,我进行了如下步骤:
1、从命令行运行PHP文件,文件名为julia.php。运行成功。运行过程如下:
php文件代码为:
<code><?php exec(" julia 12.jl"); echo "finished!"; ?> </code>
命令行运行:
同时,php文件中还有一行指令"exec('julia 12.jl')"
也执行成功了。这行代码意思是运用julia语言(一种新的编程语言)的REPL环境运行12.jl这个julia文件,12.jl运行成功的话,会在桌面输出一个txt文件。在此处txt文件也成功出现在桌面上了。
但是,当我使用浏览器,从服务器访问julia.php的时候,结果如下:
虽然最后一行代码echo "finished!"
顺利执行了,但是"exec('julia 12.jl')"
并没有执行成功,因为桌面上没有生成txt文件。
2、我百度谷歌了很久看到一个貌似是查看错误的方法,我也不是很清楚是怎么回事,抱着试试看的态度操作了一下:
php文件代码如下:
<code><?php function my_exec($cmd, $input='') {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } $str = " julia 12.jl"; //此处为我要检测是否执行成功的指令" julia 12.jl" var_export(my_exec($str)); echo "finished!"; ?> </code>
命令行运行该php文件结果:
浏览器访问结果:
百度谷歌了其中的
"ERROR:key not found: "HOMEDRIVE"
并没有找到满意的答案。
请问我这是遇到什么问题了?有什么办法能让我顺利执行该文件中的exec(" julia 12.jl")
指令么?
另外,我把其中的调用julia软件运行脚本的命令换成调用MATLAB软件的命令后,无论是在命令行还是在浏览器访问的情况下,均成功运行了MATLAB的m文件。我的php.ini
文件也关闭了安全模式。
万分期待你的解答,谢谢!
回复内容:
首先感谢抽时间阅读!
我尝试通过浏览器登陆本地服务器运行我的PHP文件,无法正常运行。我安装的是Appserver安装包2.6.0版本(Appserver网站),包内包含的软件版本为:Apache 2.2.8、PHP 6.0.0-dev。为了找出错误原因,我进行了如下步骤:
1、从命令行运行PHP文件,文件名为julia.php。运行成功。运行过程如下:
php文件代码为:
<code><?php exec(" julia 12.jl"); echo "finished!"; ?> </code>
命令行运行:
同时,php文件中还有一行指令"exec('julia 12.jl')"
也执行成功了。这行代码意思是运用julia语言(一种新的编程语言)的REPL环境运行12.jl这个julia文件,12.jl运行成功的话,会在桌面输出一个txt文件。在此处txt文件也成功出现在桌面上了。
但是,当我使用浏览器,从服务器访问julia.php的时候,结果如下:
虽然最后一行代码echo "finished!"
顺利执行了,但是"exec('julia 12.jl')"
并没有执行成功,因为桌面上没有生成txt文件。
2、我百度谷歌了很久看到一个貌似是查看错误的方法,我也不是很清楚是怎么回事,抱着试试看的态度操作了一下:
php文件代码如下:
<code><?php function my_exec($cmd, $input='') {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } $str = " julia 12.jl"; //此处为我要检测是否执行成功的指令" julia 12.jl" var_export(my_exec($str)); echo "finished!"; ?> </code>
命令行运行该php文件结果:
浏览器访问结果:
百度谷歌了其中的
"ERROR:key not found: "HOMEDRIVE"
并没有找到满意的答案。
请问我这是遇到什么问题了?有什么办法能让我顺利执行该文件中的exec(" julia 12.jl")
指令么?
另外,我把其中的调用julia软件运行脚本的命令换成调用MATLAB软件的命令后,无论是在命令行还是在浏览器访问的情况下,均成功运行了MATLAB的m文件。我的php.ini
文件也关闭了安全模式。
万分期待你的解答,谢谢!
多次尝试后,问题得以解决
解决方法:增加了两个系统环境变量:HOMEDRIVE、HOMEPATH。
之前无法解决原因:
1、不清楚Key Not Found的含义,后来尝试才知道,指的是系统的环境变量,而非Apache或者PHP的环境变量,在此感谢xelz的点拨。
2、初次尝试增加HOMEDRIVE系统环境变量,测试后没反应,其实需要重启电脑,windows就这个蛋疼。
3、初次尝试增加HOMEDRIVE系统环境变量,重启电脑后,依然报错,一开始我没注意以为还是缺少HOMEDRIVE系统环境变量,其实这次的错误略有不同,显示的是缺少HOMEPATH系统环境变量。
4、意识到以上错误后,我再次添加HOMEPATH环境变量,重启电脑后,服务器成功运行了PHP文件,成功调用Julia软件运行了jl文件。
十分感谢大家之前的热心回答。
以下答案只是猜的,希望有帮助
julia需要HOMEDRIVE
这个环境变量,命令行运行的时候是以你自己的身份运行的
但是运行apache服务器的用户没有设置这个环境变量,因此报错
不懂julia,如果你写文件用到了相对路径,可以尝试改成绝对路径
如果本来就是绝对路径,或者改成绝对路径也不行, 那么尝试在系统环境变量里设置一个HOMEDRIVE
Apache 过滤掉了一些环境变量大概?用 SetEnv 还是什么指令在配置文件里设置一下试试。
浏览器上本来就不能运行php

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software