如何通过 SSH 运行 php 脚本? [英] How do I run a php script through SSH?

查看:35
本文介绍了如何通过 SSH 运行 php 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当长的 php 脚本,每当我的互联网连接跳出一秒钟时,浏览器似乎都会停止脚本.我不能坐 8 个小时让我的脚本运行,所以我想我可以通过 ssh 运行它,然后第二天回来获取我的输出文件.然而,简单地将脚本名称输入 ssh 似乎不起作用.有没有特殊的命令可以通过ssh运行php脚本?

I have a rather long php script and whenever my internet connection skips out for a second the browser seems to stop the script. I can't sit around for 8 hours for my script to run so I figured I could just run it via ssh and be come back the next day and get my output file. However simple typing the scripts name into ssh doesn't seem to work. is there a special command to run php scripts through ssh?

推荐答案

如果您的 Internet 连接中断,那么这也可能是 SSH 的问题,而且,打开 SSH 窗口不是问题总是最好的做法(如果不小心关闭了 ssh 窗口会怎样?)

If your internet connection is dropping out, then this is probably going to be a problem across SSH as well, and well, having an SSH window open isn't always the best thing to do (what happens if you accidentally close the ssh window?)

我建议通过 SSH 连接到服务器,然后运行一个名为screen"的程序,它将继续运行您在其中运行的任何内容,即使您的连接中断.

I would suggest SSHing into the server, then running a program called "screen", which will keep on running whatever you run inside of it, even if your connection drops.

要做到这一点,首先 ssh 进入服务器,然后输入

To do this, first ssh into the server, and type

屏幕

这将加载屏幕,按回车键绕过欢迎屏幕

This will load up screen, hit enter to bypass the welcome screen

现在,运行您的 PHP 脚本

Now, run your PHP script

php/path/to/your/php/script.php

这将开始运行 PHP,

this will start PHP running,

您现在可以根据需要关闭窗口,脚本将继续运行

You can now close the window if you want, and the script will keep on running

要回到你的屏幕会话,连接到服务器,然后运行命令

To get back to your screen session, connect to the server, and run the command

screen -raAD

这将使您重新连接到您的会话,就像您一直打开窗口一样.

which will reconnect you to your session, as if you'd had the window open all the time.

这实际上非常适合运行冗长的脚本,甚至可以运行基于控制台的 IRC 会话 :D

This is actually pretty good for running long winded scripts, or even for running a console based IRC session :D

这篇关于如何通过 SSH 运行 php 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆