我正在尝试在测试服务器上复制一个网站.但是,在测试服务器上,.php文件不会被解释.我发现原因是.htaccess文档根目录中的文件.其内容:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine On
#RewriteRule ^$ index.php [QSA]
RewriteRule ^(.*)$ /web/$1
Run Code Online (Sandbox Code Playgroud)
如何配置Apache2/PHP5以支持处理程序application/x-httpd-php5s?是否有任何软件包可以使这个处理程序可用?
更新:它可能是Bluehost.com特有的处理程序.我正在调查这个......
更新2:为了避免更改.htaccess文件,这会引入不一致,我向Apache添加了一个处理程序"application/x-httpd-php5s":
AddHandler application/x-httpd-php5s .php
Action application/x-httpd-php5s /cgi-bin/php5
Run Code Online (Sandbox Code Playgroud)
但是,该处理程序将不会像生产服务器上那样运行,它会导致PHP解释器php.ini在文档根目录中使用a 并将其用于所有子目录.例如,一个有点丑陋的解决方法是将它符号链接php.ini到php.ini测试服务器上的全局.
这段小代码一直是我的一堆脚本中的主要内容,但我从其他人编写的另一个工作脚本中获取了语法,并根据我的需要对其进行了调整.我甚至不确定这里使用的语法是打开文件处理程序的最佳或最常用的方法.
代码是:
$fh = \*STAT_FILE;
open ($fh,">>".$stat_file) or die "Can't open $stat_file: $!\n";
my $print_flag = ( -z $stat_file );
Run Code Online (Sandbox Code Playgroud)
我不完全理解上面代码的第一行和最后一行.具体而言,\*STAT_FILE和-z分别.
我知道,在大多数情况下,第二行将打开一个文件以追加或退出并抛出错误.但同样,我不明白$!这条线上的服务目的是什么.
有人可以用伪线逐行解释这个Perl代码吗?另外,如果上述方法不是首选方法,那么是什么?
提前致谢
我知道存在这种问题,但我在这种情况下感到困惑.我正在使用以下代码:
package com.example.GetALocation2;
import com.example.GetALocation2.MyLocation.LocationResult;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class GetALocation2 extends Activity {
public static final String LOG_TAG = "------------------GetALocation2";
Double latitude;
TextView tv;
MyLocation myLocation = new MyLocation();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.thetext);
tv.setText("Yo there!");
Log.e(LOG_TAG, "Toast will be shown");
Toast.makeText(getBaseContext(), "This is the start!", Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, …Run Code Online (Sandbox Code Playgroud) 令我好奇的是,当我在Visual Studio ASP.NET开发服务器中运行Web应用程序时,通用处理程序工作得很好.当我更改配置以直接从IIS运行它时,处理程序就会死掉.
我真的不是这方面的专家,所以对我很不满意.
它是一个图像处理程序,它会写回要在Image对象中呈现的字节数组.正如我所说,它在VS Development Server中运行良好,但在IIS上失败.它甚至没有被称为......
我试图直接调用它时得到的错误是:
分析程序错误说明:解析为此请求提供服务所需的资源时发生错误.请查看以下特定的解析错误详细信息并相应地修改源文件.分析器错误消息:无法创建类型'YourImageHandler'.源错误:第1行:<%@ WebHandler语言="C#"CodeBehind ="YourImagehandler.ashx.cs"Class ="YourImageHandler"%>
有任何想法吗?
编辑:
更多信息:
web.config上的处理程序:
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="YourImageHandler"/>
</httpHandlers>
</system.web>
Run Code Online (Sandbox Code Playgroud)
Generic Handler与Web项目位于同一个程序集中,整个过程在IIS 7上运行.
我有一个线程,每六秒钟就会向数据库发送一次GPS坐标,并且我会检查用户是否在一个已定义的区域内.如果用户不在该位置,我想要一个警告对话框,通知他们他们超出范围,如果他们在该区域内,我想要一个告诉他们在范围内的对话框.我检查工作正常,但我已经尝试过,我很确定我无法在后台线程上添加对话框.我已经阅读了一些关于使用处理程序的内容,但我不确定如何实现它.如果您有任何建议我会很感激!谢谢.
这是我FindLocation.java从主要活动(MainActivity.java)调用的方式:
new FindLocation(getBaseContext()).start(usr_id1); //sends a user id with it
Run Code Online (Sandbox Code Playgroud)
下边是 FindLocation.java
public class FindLocation extends Thread {
public boolean inJurisdiction;
public boolean AlertNotice = false;
private LocationManager locManager;
private LocationListener locListener;
Context ctx;
public String userId;
public FindLocation(Context ctx) {
this.ctx = ctx;
}
public void start(String userId) {
this.userId = userId;
super.start();
}
@Override
public void run() {
Looper.prepare();
final String usr = userId;
//get a reference to the LocationManager
locManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); …Run Code Online (Sandbox Code Playgroud) 用户在执行下面的代码时在手机上收到错误,我在运行AsyncTaskWeb服务调用之前检查用户当前是否正在通话.我这样做的原因是因为有些人在通话时失去了互联网连接,所以我每5秒检查一次是否正在通话.如果不是,则调用AsyncTask
do{
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run() {
onCall = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
.getCallState() != TelephonyManager.CALL_STATE_IDLE;
if(!onCall){
new CallRegWS().execute();
}
}
},5000);
}while(onCall);
Run Code Online (Sandbox Code Playgroud)
我没有完整的堆栈跟踪只显示错误
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Run Code Online (Sandbox Code Playgroud)
显然不是太有帮助,但这就是我必须继续下去.他们不断得到这个错误,所以当我创建处理程序时必须发生这种错误.
所有这一切都是在main thread所以我不知道问题是什么,任何洞察我如何解决这个问题?
从服务调用此更新,该方法位于单独的类中
由于ActionBarSherlock的问题,我将我的Manifest更改为目标API 16,从那时起我检查当前正在播放的歌曲的处理程序不再有效.它在我下面标记的行上抛出NetworkOnMainThreadException.
我究竟做错了什么?我以为我的多线程设置正确.
这是我的代码:
handler = new Handler();
updateSongTask = new Runnable() {
public void run() {
Log.d("asdf", "scraper started");
Scraper scraper = new ShoutCastScraper(); // THIS LINE throws the exception
List<Stream> streams;
try {
streams = scraper.scrape(new URI(url));
for (Stream stream : streams) {
Intent songIntent = new Intent(CUSTOM_INTENT);
String[] songAndArtist = songAndArtist(stream.getCurrentSong());
songIntent.putExtra("song", songAndArtist[0]);
songIntent.putExtra("artist", songAndArtist[1]);
songIntent.putExtra("stationurl", url);
sendBroadcast(songIntent);
Log.d("asdf", "should send broadcast" );
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.postDelayed(this, …Run Code Online (Sandbox Code Playgroud) multithreading android asynchronous handler networkonmainthread
我已经创建了一个Android应用程序,当一个按钮点击处理程序时,将每隔2秒激活一个烤面包机.同样在另一方面,我有一个停止按钮,我想从中停止点击正在运行的线程
这是我的代码
private final int FIVE_SECONDS = 2000;
public void scheduleSendLocation() {
handler.postDelayed(new Runnable() {
public void run() {
sendLocation(); // this method will contain your almost-finished HTTP calls
handler.postDelayed(this, FIVE_SECONDS);
}
}, FIVE_SECONDS);
}
protected void sendLocation() {
Toast.makeText(getApplicationContext(), "Your Location is ", Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
stop = (Button) findViewById(R.id.stop);
btnShowLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
scheduleSendLocation();
}
});
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) …Run Code Online (Sandbox Code Playgroud) 我正在用Javascript编程.
我需要动态生成事件的事件处理程序onclick.
上面的代码如下:
for (var i = 1; i < CurrValue; i++) {
getId('btnReadRFIDTag_' + i).onclick = function ()
{
ReadRFIDTag(getId('txtCode_' + i));
};
}
Run Code Online (Sandbox Code Playgroud)
问题显然是在运行时i变量获得最新值而不是正确值.
但我无法解决问题,因为处理程序不允许该函数的参数.
我怎么解决这个问题?
谢谢.
祝你有美好的一天.
在我onResume()运行一个新的Handler运行以下代码行:
adapter = new FeedListAdapter(this, feed);
list.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
现在,当我将此代码移动到Handler中时,this第一行内部变得不允许,因为显然它位于runnable中,如下所示:
new Handler().postDelayed(new Runnable() {
public void run() {
adapter = new FeedListAdapter(this, feed);
list.setAdapter(adapter);
}
}, 500);
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是如何在不创建存储当前片段的方法/变量的情况下访问我所在的片段?
我通过以下方式解决了这个问题:
private FeedListActivity myInstance(){
return this;
}
Run Code Online (Sandbox Code Playgroud)
并this改为myInstance(),但这似乎是一个不好的方式.与创建存储Fragment的新变量相同.有没有办法可以调用我正在运行的片段?
也许这会清楚地说明我想做什么:
new Handler().postDelayed(new Runnable() {
public void run() {
adapter = new FeedListAdapter(getFragment(), feed);
list.setAdapter(adapter);
}
}, 500);
Run Code Online (Sandbox Code Playgroud)
所有答案都表示赞赏.