如何在 PHP 中安排/排队内容以便将来发布?
我有一个非常基本的 PHP 脚本,我用它来发布有趣的链接,我发现这些链接到我网站上的可过滤列表以及我的 rss feed(feedburner 在 ping 时也会发送推文)。
我想知道的是,添加一个“队列”,让我可以一次提交多个条目并为每个条目安排未来的发布时间/日期,会有多困难?
类似于 Twuffer 对 Twitter 或 Tumblr 和 Wordpress 已经为博客文章做好了准备。
这需要 cron 作业吗?也许我的 PHP 脚本会写入另一个文件'drafts.txt'(如果是未来的帖子) - 以及计划的 cron 来检查如果时间/日期=,然后将其写入其他文件?
我显然是这方面的新手 - 但我将不胜感激任何帮助!谢谢!
这是我当前的小脚本:
<?php
if($_POST['Submit'])
{
$category = $_POST['category'];
$linkurl = $_POST['linkurl'];
$linkname = $_POST['linkname'];
$description = $_POST['description'];
$submittername = $_POST['submittername'];
$submitterurl = $_POST['submitterurl'];
$postdate = $_POST['postdate'];
// Remove slashes.
$description = stripslashes($description);
//the data for list.txt
$data = "
<li class='$category'>
<h3><a href='$linkurl' target='_blank'>$linkname</a></h3>
<p><b>$description</b></p>
<p><small>Submitted by: <a href='$submitterurl' target='_blank'>$submittername</a><i> - $postdate</i></small></p>
</li>
";
$filename = "list.txt";
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
$New = "$data$OldData";
$fp = fopen( $filename,"w");
if(!$fp) die("Cannot write $filename .");
fwrite($fp, $New, 800000);
fclose( $fp );
//the data for rss.php
$feeddata = "
<item>
<title>Supplement: $linkname</title>
<link>$linkurl</link>
<description>$description</description>
</item>
";
$ffilename = "rss.txt";
$ff = fopen( $ffilename,"r");
$OldfeedData = fread($ff, 80000);
fclose( $ff );
$New = "$feeddata$OldfeedData";
$ff = fopen( $ffilename,"w");
if(!$ff) die("Cannot write $ffilename .");
fwrite($ff, $New, 800000);
fclose( $ff );
print("<h1>Success!</h1><a href='add.php'>Add Another?</a>");
}
?>
I have a very basic PHP script that I use to post interesting links that I find to a filterable list on my site and also to my rss feed (which feedburner then also tweets when pinged).
What I'm wondering is how hard it would be to add a 'queue' in which I could submit multiple entries at once and schedule a future time/date for each to be released?
Similar to what Twuffer does for Twitter or Tumblr and Wordpress have done for Blog Posts.
Does this require cron jobs? Perhaps with my PHP script writing another file 'drafts.txt' if it's a future post - and a scheduled cron to check if time/date =, then write it to the other files?
I'm obviously a newbie with this - but I would appreciate any help! Thanks!
Here is my current little script:
<?php
if($_POST['Submit'])
{
$category = $_POST['category'];
$linkurl = $_POST['linkurl'];
$linkname = $_POST['linkname'];
$description = $_POST['description'];
$submittername = $_POST['submittername'];
$submitterurl = $_POST['submitterurl'];
$postdate = $_POST['postdate'];
// Remove slashes.
$description = stripslashes($description);
//the data for list.txt
$data = "
<li class='$category'>
<h3><a href='$linkurl' target='_blank'>$linkname</a></h3>
<p><b>$description</b></p>
<p><small>Submitted by: <a href='$submitterurl' target='_blank'>$submittername</a><i> - $postdate</i></small></p>
</li>
";
$filename = "list.txt";
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
$New = "$data$OldData";
$fp = fopen( $filename,"w");
if(!$fp) die("Cannot write $filename .");
fwrite($fp, $New, 800000);
fclose( $fp );
//the data for rss.php
$feeddata = "
<item>
<title>Supplement: $linkname</title>
<link>$linkurl</link>
<description>$description</description>
</item>
";
$ffilename = "rss.txt";
$ff = fopen( $ffilename,"r");
$OldfeedData = fread($ff, 80000);
fclose( $ff );
$New = "$feeddata$OldfeedData";
$ff = fopen( $ffilename,"w");
if(!$ff) die("Cannot write $ffilename .");
fwrite($ff, $New, 800000);
fclose( $ff );
print("<h1>Success!</h1><a href='add.php'>Add Another?</a>");
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我最终所做的(感谢阿尔弗雷德让我朝着正确的方向思考):
效果很好!
Here's what I ended up doing (thanks to Alfred for getting me thinking in the right direction):
Works great!
我想您可以在这里阅读更多相关内容,但有一个快速总结:
我想你应该使用
at
来安排你的任务但你也可以看看 Google 应用引擎 任务队列/cron< /a> 免费安排您的任务(大量配额)。它使用 webhooks 来自动执行任务和扩展。
You could read more about this over here I guess, but a quick summary:
I guess you should use
at
to schedule your tasksBut you could also have a look at Google app engine task queue/cron to schedule your tasks for free(generous quota). It uses webhooks to execute tasks and scales automatically.